2025-02-03 17:30:50 +00:00
|
|
|
package test
|
2025-01-10 19:17:20 +00:00
|
|
|
|
|
|
|
|
import (
|
2025-02-05 17:44:01 +00:00
|
|
|
"regexp"
|
2025-01-10 19:17:20 +00:00
|
|
|
"testing"
|
|
|
|
|
|
2025-03-05 12:05:46 +00:00
|
|
|
"queryorchestration/internal/serviceconfig"
|
2025-04-02 18:50:03 +00:00
|
|
|
"queryorchestration/internal/serviceconfig/objectstore"
|
2025-03-05 12:05:46 +00:00
|
|
|
"queryorchestration/internal/serviceconfig/queue"
|
|
|
|
|
|
2025-03-17 18:14:15 +00:00
|
|
|
awsc "queryorchestration/internal/serviceconfig/aws"
|
|
|
|
|
|
2025-01-10 19:17:20 +00:00
|
|
|
"github.com/aws/aws-sdk-go-v2/aws"
|
|
|
|
|
"github.com/aws/aws-sdk-go-v2/service/sqs/types"
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
2025-03-19 11:54:14 +00:00
|
|
|
"github.com/stretchr/testify/require"
|
2025-01-10 19:17:20 +00:00
|
|
|
)
|
|
|
|
|
|
2025-04-02 18:50:03 +00:00
|
|
|
type TestConfig struct {
|
|
|
|
|
serviceconfig.BaseConfig
|
|
|
|
|
objectstore.ObjectStoreConfig
|
|
|
|
|
}
|
|
|
|
|
|
2025-02-03 17:30:50 +00:00
|
|
|
func TestCreateQueue(t *testing.T) {
|
|
|
|
|
if testing.Short() {
|
2025-05-03 01:16:53 +00:00
|
|
|
t.SkipNow()
|
2025-02-03 17:30:50 +00:00
|
|
|
}
|
2025-06-03 13:52:10 +00:00
|
|
|
ctx := t.Context()
|
2025-02-03 17:30:50 +00:00
|
|
|
|
2025-04-02 18:50:03 +00:00
|
|
|
cfg := &TestConfig{}
|
2025-02-03 17:30:50 +00:00
|
|
|
|
2025-05-23 00:20:01 +00:00
|
|
|
a := CreateAWSContainer(t, cfg)
|
2025-04-25 17:02:50 +00:00
|
|
|
SetQueueClient(t, ctx, cfg, a.ExternalEndpoint)
|
2025-02-05 12:52:41 +00:00
|
|
|
|
2025-05-23 00:20:01 +00:00
|
|
|
url := CreateQueue(t, cfg, "myname")
|
2025-05-05 09:31:21 +00:00
|
|
|
assert.Equal(t, "http://localstack:4566/queue/us-east-1/000000000000/mynametestcreatequeue", url)
|
2025-02-03 17:30:50 +00:00
|
|
|
}
|
|
|
|
|
|
2025-01-10 19:17:20 +00:00
|
|
|
func TestAssertMessageWait(t *testing.T) {
|
2025-01-17 12:00:32 +00:00
|
|
|
if testing.Short() {
|
2025-05-03 01:16:53 +00:00
|
|
|
t.SkipNow()
|
2025-01-17 12:00:32 +00:00
|
|
|
}
|
2025-06-03 13:52:10 +00:00
|
|
|
ctx := t.Context()
|
2025-01-10 19:17:20 +00:00
|
|
|
|
2025-04-02 18:50:03 +00:00
|
|
|
cfg := &TestConfig{}
|
2025-02-03 17:30:50 +00:00
|
|
|
|
2025-05-23 00:20:01 +00:00
|
|
|
a := CreateAWSContainer(t, cfg)
|
2025-04-25 17:02:50 +00:00
|
|
|
SetQueueClient(t, ctx, cfg, a.ExternalEndpoint)
|
2025-05-23 00:20:01 +00:00
|
|
|
url := CreateQueue(t, cfg, "myname")
|
2025-01-10 19:17:20 +00:00
|
|
|
|
2025-04-25 17:02:50 +00:00
|
|
|
err := cfg.SendToQueue(ctx, &queue.SendParams{
|
2025-02-03 18:51:44 +00:00
|
|
|
QueueURL: url,
|
|
|
|
|
Body: "body",
|
|
|
|
|
})
|
2025-03-19 11:54:14 +00:00
|
|
|
require.NoError(t, err)
|
2025-01-10 19:17:20 +00:00
|
|
|
|
2025-05-23 00:20:01 +00:00
|
|
|
msg := AssertMessage(t, cfg, &queue.ReceiveParams{
|
2025-02-03 18:51:44 +00:00
|
|
|
QueueURL: url,
|
|
|
|
|
})
|
2025-01-10 19:17:20 +00:00
|
|
|
assert.NotNil(t, msg)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TestAssertMessageBodyWait(t *testing.T) {
|
2025-01-17 12:00:32 +00:00
|
|
|
if testing.Short() {
|
2025-05-03 01:16:53 +00:00
|
|
|
t.SkipNow()
|
2025-01-17 12:00:32 +00:00
|
|
|
}
|
2025-06-03 13:52:10 +00:00
|
|
|
ctx := t.Context()
|
2025-01-10 19:17:20 +00:00
|
|
|
|
2025-04-02 18:50:03 +00:00
|
|
|
cfg := &TestConfig{}
|
2025-02-03 17:30:50 +00:00
|
|
|
|
2025-05-23 00:20:01 +00:00
|
|
|
a := CreateAWSContainer(t, cfg)
|
2025-04-25 17:02:50 +00:00
|
|
|
SetQueueClient(t, ctx, cfg, a.ExternalEndpoint)
|
2025-05-23 00:20:01 +00:00
|
|
|
url := CreateQueue(t, cfg, "myname")
|
2025-01-10 19:17:20 +00:00
|
|
|
|
2025-04-25 17:02:50 +00:00
|
|
|
err := cfg.SendToQueue(ctx, &queue.SendParams{
|
2025-02-03 18:51:44 +00:00
|
|
|
QueueURL: url,
|
|
|
|
|
Body: "body",
|
|
|
|
|
})
|
2025-03-19 11:54:14 +00:00
|
|
|
require.NoError(t, err)
|
2025-01-10 19:17:20 +00:00
|
|
|
|
2025-05-23 00:20:01 +00:00
|
|
|
AssertMessageBody(t, cfg, url, regexp.MustCompile("\"body\""))
|
2025-01-10 19:17:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TestAssertMessageAttrWait(t *testing.T) {
|
2025-01-17 12:00:32 +00:00
|
|
|
if testing.Short() {
|
2025-05-03 01:16:53 +00:00
|
|
|
t.SkipNow()
|
2025-01-17 12:00:32 +00:00
|
|
|
}
|
2025-06-03 13:52:10 +00:00
|
|
|
ctx := t.Context()
|
2025-01-10 19:17:20 +00:00
|
|
|
|
2025-04-02 18:50:03 +00:00
|
|
|
cfg := &TestConfig{}
|
2025-02-03 17:30:50 +00:00
|
|
|
|
2025-05-23 00:20:01 +00:00
|
|
|
a := CreateAWSContainer(t, cfg)
|
2025-04-25 17:02:50 +00:00
|
|
|
SetQueueClient(t, ctx, cfg, a.ExternalEndpoint)
|
2025-05-23 00:20:01 +00:00
|
|
|
url := CreateQueue(t, cfg, "myname")
|
2025-01-10 19:17:20 +00:00
|
|
|
|
|
|
|
|
name := "name"
|
|
|
|
|
value := "value"
|
|
|
|
|
|
2025-04-25 17:02:50 +00:00
|
|
|
err := cfg.SendToQueue(ctx, &queue.SendParams{
|
2025-02-03 18:51:44 +00:00
|
|
|
QueueURL: url,
|
|
|
|
|
Body: "body",
|
|
|
|
|
Attributes: map[string]types.MessageAttributeValue{
|
|
|
|
|
name: {
|
|
|
|
|
DataType: aws.String("String"),
|
|
|
|
|
StringValue: aws.String(value),
|
|
|
|
|
},
|
2025-01-10 19:17:20 +00:00
|
|
|
},
|
|
|
|
|
})
|
2025-03-19 11:54:14 +00:00
|
|
|
require.NoError(t, err)
|
2025-01-10 19:17:20 +00:00
|
|
|
|
2025-05-23 00:20:01 +00:00
|
|
|
AssertMessageAttr(t, cfg, url, name, regexp.MustCompile(value))
|
2025-01-10 19:17:20 +00:00
|
|
|
}
|
2025-03-17 18:14:15 +00:00
|
|
|
|
|
|
|
|
func TestGetQueueURL(t *testing.T) {
|
|
|
|
|
cfg := &awsc.AWSConfig{
|
|
|
|
|
AWSRegion: "us-east-1",
|
|
|
|
|
}
|
2025-05-05 09:31:21 +00:00
|
|
|
assert.Equal(t, "http://localstack:4566/queue/us-east-1/000000000000/docinitrunnertestgetqueueurl", GetQueueURL(t, cfg, DocInitRunnerName))
|
2025-03-17 18:14:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TestGetQueueARN(t *testing.T) {
|
|
|
|
|
cfg := &awsc.AWSConfig{
|
|
|
|
|
AWSRegion: "us-east-1",
|
|
|
|
|
}
|
2025-05-05 09:31:21 +00:00
|
|
|
assert.Equal(t, "arn:aws:sqs:us-east-1:000000000000:docinitrunnertestgetqueuearn", GetQueueArn(t, cfg, DocInitRunnerName))
|
2025-03-17 18:14:15 +00:00
|
|
|
}
|