diff options
-rw-r--r-- | aws.go | 26 | ||||
-rw-r--r-- | internal/pipeline/pipeline_test.go | 11 | ||||
-rw-r--r-- | local.go | 5 |
3 files changed, 26 insertions, 16 deletions
@@ -51,6 +51,7 @@ type AwsConn struct { downloader *s3manager.Downloader uploader *s3manager.Uploader wipequrl, prequrl, ocrpgqurl, analysequrl string + testqurl string wipstorageid string } @@ -128,6 +129,19 @@ func (a *AwsConn) Init() error { return nil } +// TestInit initialises extra aws services needed for running tests. +func (a *AwsConn) TestInit() error { + a.Logger.Println("Getting test queue URL") + result, err := a.sqssvc.GetQueueUrl(&sqs.GetQueueUrlInput{ + QueueName: aws.String(queueTest), + }) + if err != nil { + return errors.New(fmt.Sprintf("Error getting test queue URL: %s\n", err)) + } + a.testqurl = *result.QueueUrl + return nil +} + func (a *AwsConn) CheckQueue(url string, timeout int64) (Qmsg, error) { msgResult, err := a.sqssvc.ReceiveMessage(&sqs.ReceiveMessageInput{ MaxNumberOfMessages: aws.Int64(1), @@ -337,17 +351,7 @@ func (a *AwsConn) WIPStorageId() string { } func (a *AwsConn) TestQueueId() string { - // We don't bother saving the queue id in Init(), as it's only - // used for testing - a.Logger.Println("Getting test queue URL") - result, err := a.sqssvc.GetQueueUrl(&sqs.GetQueueUrlInput{ - QueueName: aws.String(queueTest), - }) - if err != nil { - a.Logger.Printf("Error getting test queue URL: %s\n", err) - return "" - } - return *result.QueueUrl + return a.testqurl } func (a *AwsConn) ListObjects(bucket string, prefix string) ([]string, error) { diff --git a/internal/pipeline/pipeline_test.go b/internal/pipeline/pipeline_test.go index 4a08d3b..73e8223 100644 --- a/internal/pipeline/pipeline_test.go +++ b/internal/pipeline/pipeline_test.go @@ -30,6 +30,7 @@ func (t *StrLog) Write(p []byte) (n int, err error) { type PipelineTester interface { Pipeliner + TestInit() error DeleteObjects(bucket string, keys []string) error TestQueueId() string } @@ -309,6 +310,10 @@ func Test_upAndQueue(t *testing.T) { if err != nil { t.Fatalf("Could not initialise %s connection: %v\nLog: %s", conn.name, err, slog.log) } + err = conn.c.TestInit() + if err != nil { + t.Fatalf("Failed in test initialisation for %s: %v\nLog: %s", conn.name, err, slog.log) + } slog.log = "" tempDir := filepath.Join(os.TempDir(), "pipelinetest") err = os.MkdirAll(tempDir, 0700) @@ -390,11 +395,7 @@ func Test_upAndQueue(t *testing.T) { t.Fatalf("Uploaded file differs from expected, expected: '%s', got '%s'\nLog: %s", c.contents, dled, slog.log) } - target, err := filepath.Rel(os.TempDir(), filepath.Join(tempDir, c.ul)) - if err != nil { - t.Fatalf("Error removing TempDir prefix: %v", err) - } - queueExpected := target + " test" + queueExpected := "pipelinetest/" + c.ul + " test" if msg.Body != queueExpected { _ = conn.c.DelFromQueue(queueurl, msg.Handle) t.Fatalf("Queue contents not as expected, expected: '%s', got '%s'\nLog: %s", queueExpected, msg.Body, slog.log) @@ -64,6 +64,11 @@ func (a *LocalConn) Init() error { return nil } +// TestInit does nothing for local connections +func (a *LocalConn) TestInit() error { + return nil +} + // CheckQueue checks for any messages in a queue func (a *LocalConn) CheckQueue(url string, timeout int64) (Qmsg, error) { f, err := os.Open(filepath.Join(a.TempDir, url)) |