Files
SQS-service/app/models/models_test.go
T
Naeel c3ba2dcae4 chore: initial import from sless/shared-sqs (v0.1.14)
- Standalone SQS-service repository
- Multi-tenant message queue service, AWS SQS compatible
- Based on GoAws, with mutable tenants, auth, WebUI, Redis persistence
- Ready for independent development and deployment
- See doc/ and README.md for architecture and usage
2026-04-10 16:47:27 +03:00

74 lines
1.8 KiB
Go

package models
import (
"testing"
"time"
"github.com/stretchr/testify/assert"
)
func TestFilterPolicy_IsSatisfiedBy(t *testing.T) {
var tests = []struct {
filterPolicy *FilterPolicy
messageAttributes map[string]MessageAttribute
expected bool
}{
{
&FilterPolicy{"foo": {"bar"}},
map[string]MessageAttribute{"foo": {DataType: "String", StringValue: "bar"}},
true,
},
{
&FilterPolicy{"foo": {"bar", "xyz"}},
map[string]MessageAttribute{"foo": {DataType: "String", StringValue: "xyz"}},
true,
},
{
&FilterPolicy{"foo": {"bar", "xyz"}, "abc": {"def"}},
map[string]MessageAttribute{"foo": {DataType: "String", StringValue: "xyz"},
"abc": {DataType: "String", StringValue: "def"}},
true,
},
{
&FilterPolicy{"foo": {"bar"}},
map[string]MessageAttribute{"foo": {DataType: "String", StringValue: "baz"}},
false,
},
{
&FilterPolicy{"foo": {"bar"}},
map[string]MessageAttribute{},
false,
},
{
&FilterPolicy{"foo": {"bar"}, "abc": {"def"}},
map[string]MessageAttribute{"foo": {DataType: "String", StringValue: "bar"}},
false,
},
{
&FilterPolicy{"foo": {"bar"}},
map[string]MessageAttribute{"foo": {DataType: "Binary", BinaryValue: "bar"}},
false,
},
}
for i, tt := range tests {
actual := tt.filterPolicy.IsSatisfiedBy(tt.messageAttributes)
if tt.filterPolicy.IsSatisfiedBy(tt.messageAttributes) != tt.expected {
t.Errorf("#%d FilterPolicy: expected %t, actual %t", i, tt.expected, actual)
}
}
}
func TestMessage_IsReadyForReceipt(t *testing.T) {
CurrentEnvironment.RandomLatency.Min = 100
CurrentEnvironment.RandomLatency.Max = 100
msg := SqsMessage{
SentTime: time.Now(),
}
assert.False(t, msg.IsReadyForReceipt())
duration, _ := time.ParseDuration("105ms")
time.Sleep(duration)
assert.True(t, msg.IsReadyForReceipt())
}