00e7dca3c7
Move queue to config * movequeue * passtests
142 lines
2.9 KiB
Go
142 lines
2.9 KiB
Go
package test
|
|
|
|
import (
|
|
"context"
|
|
"queryorchestration/internal/serviceconfig/queue"
|
|
"testing"
|
|
|
|
"github.com/aws/aws-sdk-go-v2/aws"
|
|
"github.com/aws/aws-sdk-go-v2/service/sqs/types"
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
func TestCreateQueueContainer(t *testing.T) {
|
|
if testing.Short() {
|
|
t.Skip("Skipping long test in short mode")
|
|
}
|
|
ctx := context.Background()
|
|
cfg := CreateBaseConfig()
|
|
|
|
qcfg, cleanup := createQueueContainer(t, ctx, &CreateQueueConfig{
|
|
Cfg: cfg,
|
|
})
|
|
assert.NotNil(t, qcfg)
|
|
assert.NotNil(t, cleanup)
|
|
|
|
cleanup()
|
|
}
|
|
|
|
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)
|
|
}
|
|
|
|
func TestAssertMessageWait(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")
|
|
|
|
err := cfg.SendToQueue(ctx, &queue.SendParams{
|
|
QueueURL: url,
|
|
Body: "body",
|
|
})
|
|
assert.NoError(t, err)
|
|
|
|
msg := AssertMessageWait(t, ctx, cfg, &queue.ReceiveParams{
|
|
QueueURL: url,
|
|
})
|
|
assert.NotNil(t, msg)
|
|
}
|
|
|
|
func TestAssertMessageBodyWait(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")
|
|
|
|
err := cfg.SendToQueue(ctx, &queue.SendParams{
|
|
QueueURL: url,
|
|
Body: "body",
|
|
})
|
|
assert.NoError(t, err)
|
|
|
|
AssertMessageBodyWait(t, ctx, cfg, url, "\"body\"")
|
|
}
|
|
|
|
func TestAssertMessageAttrWait(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")
|
|
|
|
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),
|
|
},
|
|
},
|
|
})
|
|
assert.NoError(t, err)
|
|
|
|
AssertMessageAttrWait(t, ctx, cfg, url, name, value)
|
|
}
|