721ca8a6e6
Dockerfile in Test * dockerfile * network * const
141 lines
3.0 KiB
Go
141 lines
3.0 KiB
Go
package test
|
|
|
|
import (
|
|
"context"
|
|
"regexp"
|
|
"testing"
|
|
|
|
"queryorchestration/internal/serviceconfig"
|
|
"queryorchestration/internal/serviceconfig/objectstore"
|
|
"queryorchestration/internal/serviceconfig/queue"
|
|
|
|
awsc "queryorchestration/internal/serviceconfig/aws"
|
|
|
|
"github.com/aws/aws-sdk-go-v2/aws"
|
|
"github.com/aws/aws-sdk-go-v2/service/sqs/types"
|
|
"github.com/stretchr/testify/assert"
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
type TestConfig struct {
|
|
serviceconfig.BaseConfig
|
|
objectstore.ObjectStoreConfig
|
|
}
|
|
|
|
func TestCreateQueue(t *testing.T) {
|
|
t.Parallel()
|
|
if testing.Short() {
|
|
t.SkipNow()
|
|
}
|
|
ctx := context.Background()
|
|
|
|
cfg := &TestConfig{}
|
|
|
|
net := GetNetwork(t, ctx)
|
|
|
|
a := CreateAWSContainer(t, ctx, cfg, net)
|
|
|
|
SetQueueClient(t, ctx, cfg, a.ExternalEndpoint)
|
|
|
|
url := CreateQueue(t, ctx, cfg, "myname")
|
|
assert.Equal(t, "http://localstack:4566/queue/us-east-1/000000000000/myname_testcreatequeue", url)
|
|
}
|
|
|
|
func TestAssertMessageWait(t *testing.T) {
|
|
t.Parallel()
|
|
if testing.Short() {
|
|
t.SkipNow()
|
|
}
|
|
ctx := context.Background()
|
|
|
|
cfg := &TestConfig{}
|
|
|
|
net := GetNetwork(t, ctx)
|
|
|
|
a := CreateAWSContainer(t, ctx, cfg, net)
|
|
SetQueueClient(t, ctx, cfg, a.ExternalEndpoint)
|
|
url := CreateQueue(t, ctx, cfg, "myname")
|
|
|
|
err := cfg.SendToQueue(ctx, &queue.SendParams{
|
|
QueueURL: url,
|
|
Body: "body",
|
|
})
|
|
require.NoError(t, err)
|
|
|
|
msg := AssertMessage(t, ctx, cfg, &queue.ReceiveParams{
|
|
QueueURL: url,
|
|
})
|
|
assert.NotNil(t, msg)
|
|
}
|
|
|
|
func TestAssertMessageBodyWait(t *testing.T) {
|
|
t.Parallel()
|
|
if testing.Short() {
|
|
t.SkipNow()
|
|
}
|
|
ctx := context.Background()
|
|
|
|
cfg := &TestConfig{}
|
|
|
|
net := GetNetwork(t, ctx)
|
|
|
|
a := CreateAWSContainer(t, ctx, cfg, net)
|
|
SetQueueClient(t, ctx, cfg, a.ExternalEndpoint)
|
|
url := CreateQueue(t, ctx, cfg, "myname")
|
|
|
|
err := cfg.SendToQueue(ctx, &queue.SendParams{
|
|
QueueURL: url,
|
|
Body: "body",
|
|
})
|
|
require.NoError(t, err)
|
|
|
|
AssertMessageBody(t, ctx, cfg, url, regexp.MustCompile("\"body\""))
|
|
}
|
|
|
|
func TestAssertMessageAttrWait(t *testing.T) {
|
|
t.Parallel()
|
|
if testing.Short() {
|
|
t.SkipNow()
|
|
}
|
|
ctx := context.Background()
|
|
|
|
cfg := &TestConfig{}
|
|
|
|
net := GetNetwork(t, ctx)
|
|
|
|
a := CreateAWSContainer(t, ctx, cfg, net)
|
|
SetQueueClient(t, ctx, cfg, a.ExternalEndpoint)
|
|
url := CreateQueue(t, ctx, cfg, "myname")
|
|
|
|
name := "name"
|
|
value := "value"
|
|
|
|
err := cfg.SendToQueue(ctx, &queue.SendParams{
|
|
QueueURL: url,
|
|
Body: "body",
|
|
Attributes: map[string]types.MessageAttributeValue{
|
|
name: {
|
|
DataType: aws.String("String"),
|
|
StringValue: aws.String(value),
|
|
},
|
|
},
|
|
})
|
|
require.NoError(t, err)
|
|
|
|
AssertMessageAttr(t, ctx, cfg, url, name, regexp.MustCompile(value))
|
|
}
|
|
|
|
func TestGetQueueURL(t *testing.T) {
|
|
cfg := &awsc.AWSConfig{
|
|
AWSRegion: "us-east-1",
|
|
}
|
|
assert.Equal(t, "http://localstack:4566/queue/us-east-1/000000000000/docinitrunner_testgetqueueurl", GetQueueURL(t, cfg, DocInitRunnerName))
|
|
}
|
|
|
|
func TestGetQueueARN(t *testing.T) {
|
|
cfg := &awsc.AWSConfig{
|
|
AWSRegion: "us-east-1",
|
|
}
|
|
assert.Equal(t, "arn:aws:sqs:us-east-1:000000000000:docinitrunner_testgetqueuearn", GetQueueArn(t, cfg, DocInitRunnerName))
|
|
}
|