loader_test.go 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. package loader_test
  2. import (
  3. "os"
  4. "strings"
  5. "testing"
  6. "github.com/cloudflare/mitmengine"
  7. "github.com/cloudflare/mitmengine/loader"
  8. )
  9. func TestProcessorConfigS3(t *testing.T) {
  10. variables := []string{
  11. "AWS_SECRET_ACCESS_KEY",
  12. "AWS_ACCESS_KEY_ID",
  13. "AWS_ENDPOINT",
  14. "AWS_BUCKET_NAME",
  15. }
  16. skip := false
  17. for _, v := range variables {
  18. if _, ok := os.LookupEnv(v); !ok {
  19. skip = true
  20. }
  21. }
  22. if skip {
  23. t.Skipf("To run this test, set the following environment variables: %v", strings.Join(variables, ", "))
  24. }
  25. s3Instance, err := loader.NewS3Instance()
  26. if err != nil {
  27. t.Fatalf("loader.NewS3Instance(): '%v'", err)
  28. }
  29. testConfigS3 := mitmengine.Config{
  30. BrowserFileName: "browser.txt",
  31. MitmFileName: "mitm.txt",
  32. BadHeaderFileName: "badheader.txt",
  33. Loader: s3Instance,
  34. }
  35. t.Run("LoaderThrowsErrFileNNonexistent", func(t *testing.T) { _TestLoaderThrowsErrFileNNonexistent(t, &testConfigS3) })
  36. t.Run("TestLoaderLoadsExistingFile", func(t *testing.T) { _TestLoaderLoadsExistingFile(t, &testConfigS3) })
  37. }
  38. // Please edit this function to represent .txt files you DON'T expect to find in your data store
  39. func _TestLoaderThrowsErrFileNNonexistent(t *testing.T, config *mitmengine.Config) {
  40. fakeFile := "not-real.txt"
  41. _, loadFileErr := config.Loader.LoadFile(fakeFile)
  42. if loadFileErr == nil {
  43. t.Fatal("s3 instance retrieves fake file not-real.txt:", loadFileErr)
  44. }
  45. }
  46. // Please edit this function to represent .txt files you DO expect to find in your data store
  47. func _TestLoaderLoadsExistingFile(t *testing.T, config *mitmengine.Config) {
  48. realFile := "browser.txt"
  49. _, loadFileErr := config.Loader.LoadFile(realFile)
  50. if loadFileErr != nil {
  51. t.Fatal("s3 instance cannot retrieve real file browser.txt:", loadFileErr)
  52. }
  53. }