1
0
mirror of https://github.com/go-micro/go-micro.git synced 2025-02-16 18:34:33 +02:00
go-micro/plugins/broker/snssqs/snssqs_test.go
2020-12-26 15:32:45 +00:00

35 lines
1.1 KiB
Go

package snssqs
import (
"testing"
"github.com/micro/go-micro/v2/broker"
)
func TestValidate(t *testing.T) {
tests := []struct {
name string
msg *broker.Message
wantErr bool
}{
{"Empty", &broker.Message{Body: []byte("")}, false},
{"Accept1", &broker.Message{Body: []byte("\u0009")}, false},
{"Accept2", &broker.Message{Body: []byte("\u000a")}, false},
{"Accept3", &broker.Message{Body: []byte("\u000a\u0009")}, false},
{"Reject1", &broker.Message{Body: []byte("\u0007")}, true},
{"Reject2", &broker.Message{Body: []byte("\u0009\u0007")}, true},
{"Reject3", &broker.Message{Body: []byte("\u0007\u0009")}, true},
{"Longer1", &broker.Message{Body: []byte(
"This is a longer valid unicode string that should test that workers process runes correctly.")}, false},
{"Longer2", &broker.Message{Body: []byte(
"This is a longer unicode string containing an invalid character \u0007 that should test the inverse.")}, true},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if err := ValidateBody(tt.msg); (err != nil) != tt.wantErr {
t.Errorf("ValidateBody() error = %v, wantErr %v", err, tt.wantErr)
}
})
}
}