2025-02-03 17:30:50 +00:00
|
|
|
package test
|
2025-01-10 19:17:20 +00:00
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"context"
|
2025-01-17 12:00:32 +00:00
|
|
|
"queryorchestration/internal/server/queue"
|
2025-01-10 19:17:20 +00:00
|
|
|
"testing"
|
|
|
|
|
|
|
|
|
|
"github.com/aws/aws-sdk-go-v2/aws"
|
|
|
|
|
"github.com/aws/aws-sdk-go-v2/service/sqs/types"
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
|
)
|
|
|
|
|
|
2025-02-03 17:30:50 +00:00
|
|
|
func TestCreateQueueContainer(t *testing.T) {
|
2025-01-17 12:00:32 +00:00
|
|
|
if testing.Short() {
|
|
|
|
|
t.Skip("Skipping long test in short mode")
|
|
|
|
|
}
|
2025-01-10 19:17:20 +00:00
|
|
|
ctx := context.Background()
|
2025-02-03 17:30:50 +00:00
|
|
|
cfg := CreateBaseConfig()
|
2025-01-10 19:17:20 +00:00
|
|
|
|
2025-02-03 17:30:50 +00:00
|
|
|
qcfg, cleanup := createQueueContainer(t, ctx, &CreateQueueConfig{
|
|
|
|
|
Cfg: cfg,
|
|
|
|
|
})
|
2025-01-10 19:17:20 +00:00
|
|
|
assert.NotNil(t, qcfg)
|
|
|
|
|
assert.NotNil(t, cleanup)
|
|
|
|
|
|
|
|
|
|
cleanup()
|
|
|
|
|
}
|
|
|
|
|
|
2025-02-03 17:30:50 +00:00
|
|
|
func TestCreateQueueClient(t *testing.T) {
|
|
|
|
|
if testing.Short() {
|
|
|
|
|
t.Skip("Skipping long test in short mode")
|
|
|
|
|
}
|
|
|
|
|
ctx := context.Background()
|
|
|
|
|
cfg := CreateBaseConfig()
|
|
|
|
|
|
|
|
|
|
cleanup := CreateQueueClient(t, ctx, &CreateQueueConfig{
|
|
|
|
|
Cfg: cfg,
|
|
|
|
|
})
|
|
|
|
|
assert.NotNil(t, cfg.QueueClient)
|
|
|
|
|
assert.NotNil(t, cleanup)
|
|
|
|
|
|
|
|
|
|
cleanup()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TestCreateQueue(t *testing.T) {
|
|
|
|
|
if testing.Short() {
|
|
|
|
|
t.Skip("Skipping long test in short mode")
|
|
|
|
|
}
|
|
|
|
|
ctx := context.Background()
|
|
|
|
|
|
|
|
|
|
cfg := CreateBaseConfig()
|
|
|
|
|
|
|
|
|
|
cleanup := CreateQueueClient(t, ctx, &CreateQueueConfig{
|
|
|
|
|
Cfg: cfg,
|
|
|
|
|
})
|
|
|
|
|
defer cleanup()
|
|
|
|
|
|
|
|
|
|
url := CreateQueue(t, ctx, cfg, "myname")
|
|
|
|
|
assert.Equal(t, "http://localstack:4566/queue/us-east-1/000000000000/myname", url)
|
|
|
|
|
}
|
|
|
|
|
|
2025-01-10 19:17:20 +00:00
|
|
|
func TestAssertMessageWait(t *testing.T) {
|
2025-01-17 12:00:32 +00:00
|
|
|
if testing.Short() {
|
|
|
|
|
t.Skip("Skipping long test in short mode")
|
|
|
|
|
}
|
2025-01-10 19:17:20 +00:00
|
|
|
ctx := context.Background()
|
|
|
|
|
|
2025-02-03 17:30:50 +00:00
|
|
|
cfg := CreateBaseConfig()
|
|
|
|
|
|
|
|
|
|
cleanup := CreateQueueClient(t, ctx, &CreateQueueConfig{
|
|
|
|
|
Cfg: cfg,
|
|
|
|
|
})
|
2025-01-10 19:17:20 +00:00
|
|
|
defer cleanup()
|
2025-02-03 17:30:50 +00:00
|
|
|
url := CreateQueue(t, ctx, cfg, "myname")
|
2025-01-10 19:17:20 +00:00
|
|
|
|
2025-02-03 17:30:50 +00:00
|
|
|
qucfg := &queue.Config{
|
|
|
|
|
URL: url,
|
|
|
|
|
Client: cfg.QueueClient,
|
2025-01-10 19:17:20 +00:00
|
|
|
}
|
|
|
|
|
|
2025-02-03 17:30:50 +00:00
|
|
|
err := queue.Send(ctx, qucfg, "body", map[string]types.MessageAttributeValue{})
|
|
|
|
|
assert.NoError(t, err)
|
2025-01-10 19:17:20 +00:00
|
|
|
|
2025-02-03 17:30:50 +00:00
|
|
|
msg := AssertMessageWait(t, ctx, qucfg, []string{})
|
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() {
|
|
|
|
|
t.Skip("Skipping long test in short mode")
|
|
|
|
|
}
|
2025-01-10 19:17:20 +00:00
|
|
|
ctx := context.Background()
|
|
|
|
|
|
2025-02-03 17:30:50 +00:00
|
|
|
cfg := CreateBaseConfig()
|
|
|
|
|
|
|
|
|
|
cleanup := CreateQueueClient(t, ctx, &CreateQueueConfig{
|
|
|
|
|
Cfg: cfg,
|
|
|
|
|
})
|
2025-01-10 19:17:20 +00:00
|
|
|
defer cleanup()
|
2025-02-03 17:30:50 +00:00
|
|
|
url := CreateQueue(t, ctx, cfg, "myname")
|
2025-01-10 19:17:20 +00:00
|
|
|
|
2025-02-03 17:30:50 +00:00
|
|
|
qucfg := &queue.Config{
|
|
|
|
|
URL: url,
|
|
|
|
|
Client: cfg.QueueClient,
|
2025-01-10 19:17:20 +00:00
|
|
|
}
|
|
|
|
|
|
2025-02-03 17:30:50 +00:00
|
|
|
err := queue.Send(ctx, qucfg, "body", map[string]types.MessageAttributeValue{})
|
|
|
|
|
assert.NoError(t, err)
|
2025-01-10 19:17:20 +00:00
|
|
|
|
2025-02-03 17:30:50 +00:00
|
|
|
AssertMessageBodyWait(t, ctx, qucfg, "\"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() {
|
|
|
|
|
t.Skip("Skipping long test in short mode")
|
|
|
|
|
}
|
2025-01-10 19:17:20 +00:00
|
|
|
ctx := context.Background()
|
|
|
|
|
|
2025-02-03 17:30:50 +00:00
|
|
|
cfg := CreateBaseConfig()
|
|
|
|
|
|
|
|
|
|
cleanup := CreateQueueClient(t, ctx, &CreateQueueConfig{
|
|
|
|
|
Cfg: cfg,
|
|
|
|
|
})
|
2025-01-10 19:17:20 +00:00
|
|
|
defer cleanup()
|
2025-02-03 17:30:50 +00:00
|
|
|
url := CreateQueue(t, ctx, cfg, "myname")
|
2025-01-10 19:17:20 +00:00
|
|
|
|
2025-02-03 17:30:50 +00:00
|
|
|
qucfg := &queue.Config{
|
|
|
|
|
URL: url,
|
|
|
|
|
Client: cfg.QueueClient,
|
2025-01-10 19:17:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
name := "name"
|
|
|
|
|
value := "value"
|
|
|
|
|
|
2025-02-03 17:30:50 +00:00
|
|
|
err := queue.Send(ctx, qucfg, "body", map[string]types.MessageAttributeValue{
|
2025-01-10 19:17:20 +00:00
|
|
|
name: {
|
|
|
|
|
DataType: aws.String("String"),
|
|
|
|
|
StringValue: aws.String(value),
|
|
|
|
|
},
|
|
|
|
|
})
|
2025-02-03 17:30:50 +00:00
|
|
|
assert.NoError(t, err)
|
2025-01-10 19:17:20 +00:00
|
|
|
|
2025-02-03 17:30:50 +00:00
|
|
|
AssertMessageAttrWait(t, ctx, qucfg, name, value)
|
2025-01-10 19:17:20 +00:00
|
|
|
}
|