loader_test.go 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. package loader_test
  2. import (
  3. "github.com/cloudflare/mitmengine"
  4. "github.com/cloudflare/mitmengine/loader"
  5. "os"
  6. "testing"
  7. )
  8. func TestProcessorConfigS3(t *testing.T) {
  9. configFileName := "s3cfg.toml"
  10. _, notInLocalDirErr := os.Stat("./" + configFileName)
  11. _, notInProjectRootDirErr := os.Stat("../" + configFileName)
  12. // This test will be a no-op if no s3cfg.toml file is provided in the loader directory or the project's
  13. // root directory.
  14. if os.IsNotExist(notInLocalDirErr) && os.IsNotExist(notInProjectRootDirErr) {
  15. t.Skip(`No s3cfg.toml file found in project root directory
  16. ($GOPATH/src/github.com/cloudflare/mitmengine) or loaders directory`)
  17. }
  18. s3Instance, err := loader.NewS3Instance(configFileName)
  19. if err != nil {
  20. t.Fatal("Could not load s3 instance:", err)
  21. }
  22. testConfigS3 := mitmengine.Config{
  23. BrowserFileName: "browser.txt",
  24. MitmFileName: "mitm.txt",
  25. BadHeaderFileName: "badheader.txt",
  26. Loader: s3Instance,
  27. }
  28. t.Run("LoaderThrowsErrFileNNonexistent", func(t *testing.T) { _TestLoaderThrowsErrFileNNonexistent(t, &testConfigS3) })
  29. t.Run("TestLoaderLoadsExistingFile", func(t *testing.T) { _TestLoaderLoadsExistingFile(t, &testConfigS3) })
  30. }
  31. // Please edit this function to represent .txt files you DON'T expect to find in your data store
  32. func _TestLoaderThrowsErrFileNNonexistent(t *testing.T, config *mitmengine.Config) {
  33. fakeFile := "not-real.txt"
  34. _, loadFileErr := config.Loader.LoadFile(fakeFile)
  35. if loadFileErr == nil {
  36. t.Fatal("s3 instance retrieves fake file not-real.txt:", loadFileErr)
  37. }
  38. }
  39. // Please edit this function to represent .txt files you DO expect to find in your data store
  40. func _TestLoaderLoadsExistingFile(t *testing.T, config *mitmengine.Config) {
  41. realFile := "browser.txt"
  42. _, loadFileErr := config.Loader.LoadFile(realFile)
  43. if loadFileErr != nil {
  44. t.Fatal("s3 instance cannot retrieve real file browser.txt:", loadFileErr)
  45. }
  46. }