From 530a16a460ddd69e9750841f237a35272b70fccc Mon Sep 17 00:00:00 2001 From: Justin Casso Date: Sat, 9 Oct 2021 00:05:39 -0700 Subject: [PATCH] Add e2e tests --- .vscode/launch.json | 8 +++++ Makefile | 3 ++ e2e/conduit_test.go | 13 +++++++ e2e/helpers.go | 82 +++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 106 insertions(+) create mode 100644 e2e/conduit_test.go create mode 100644 e2e/helpers.go diff --git a/.vscode/launch.json b/.vscode/launch.json index aaa446f..60e72f8 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -10,6 +10,14 @@ "request": "launch", "mode": "auto", "program": "main.go" + }, + { + "name": "Launch e2e tests", + "type": "go", + "request": "launch", + "mode": "auto", + "program": "test", + "args": ["./e2e"] } ] } \ No newline at end of file diff --git a/Makefile b/Makefile index e50242d..6c28b2b 100644 --- a/Makefile +++ b/Makefile @@ -3,3 +3,6 @@ run: build: go build -o bin/main main.go + +test: + go test -v ./e2e/ diff --git a/e2e/conduit_test.go b/e2e/conduit_test.go new file mode 100644 index 0000000..589ffd5 --- /dev/null +++ b/e2e/conduit_test.go @@ -0,0 +1,13 @@ +package conduit + +import ( + "testing" +) + +func TestProcessing(t *testing.T) { + describe("Processing", t) + + // ch := make(chan conduit.Transformable, 3) + generateFiles("ingress", 3, "test-file") + // data := conduit.Extract(, ch) +} diff --git a/e2e/helpers.go b/e2e/helpers.go new file mode 100644 index 0000000..3eb682b --- /dev/null +++ b/e2e/helpers.go @@ -0,0 +1,82 @@ +package conduit + +import ( + "encoding/json" + "fmt" + "strings" + "sync" + "testing" + + "github.com/aws/aws-sdk-go/aws" + "github.com/aws/aws-sdk-go/aws/session" + "github.com/aws/aws-sdk-go/service/s3/s3manager" +) + +type TestStruct struct { + TestString string + TestInt int + TestBool bool +} + +func expectEqualInts(value int, expectation int, t *testing.T) { + if value != expectation { + t.Errorf("Failed: expected %d, but found %d", value, expectation) + } +} + +func expectEqualStrings(value string, expectation string, t *testing.T) { + if value != expectation { + t.Errorf("Failed: expected %s, but found %s", value, expectation) + } +} + +func describe(functionName string, t *testing.T) { + t.Logf("%s:", functionName) +} + +func it(description string, t *testing.T) { + t.Logf(" - it %s", description) +} + +func context(description string, t *testing.T) { + t.Logf(" - when %s", description) +} + +func generateFiles(bucket string, count int, filePrefix string) { + var wg sync.WaitGroup + sess := session.Must(session.NewSessionWithOptions(session.Options{ + SharedConfigState: session.SharedConfigEnable, + Config: aws.Config{ + S3ForcePathStyle: aws.Bool(true), + Region: aws.String("us-east-1"), + Endpoint: aws.String("http://localstack:4566"), + }, + })) + uploader := s3manager.NewUploader(sess) + + for i := 1; i <= count; i++ { + wg.Add(1) + go func(j int, uploader *s3manager.Uploader, filePrefix string) { + defer wg.Done() + + data := TestStruct{ + TestBool: j == 1, + TestString: "foo", + TestInt: j, + } + human_enc, err := json.Marshal(data) + if err != nil { + fmt.Println(err) + } + + key := fmt.Sprintf("%s%d", filePrefix, j) + body := string(human_enc) + uploader.Upload(&s3manager.UploadInput{ + Bucket: aws.String(bucket), + Key: aws.String(key), + Body: strings.NewReader(body), + }) + }(i, uploader, filePrefix) + } + wg.Wait() +}