31 lines
837 B
Go
31 lines
837 B
Go
package postgres
|
|
|
|
import (
|
|
"strings"
|
|
"testing"
|
|
|
|
"github.com/samcharles93/archie-core/internal/domain/alert"
|
|
)
|
|
|
|
// The lock key is sent to Postgres as text, which rejects a NUL byte.
|
|
func TestAlertLockKeyHasNoNUL(t *testing.T) {
|
|
keys := []alert.Key{
|
|
{Org: "org", Kind: "provider.no_credential", Subject: "openai"},
|
|
{Org: "", Kind: "", Subject: ""},
|
|
{Org: "a", Kind: "b", Subject: "c\x00d"},
|
|
}
|
|
for _, k := range keys {
|
|
if got := alertLockKey(k); strings.Contains(got, "\x00") {
|
|
t.Errorf("alertLockKey(%+v) = %q contains a NUL byte", k, got)
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestAlertLockKeyDistinguishesFields(t *testing.T) {
|
|
a := alertLockKey(alert.Key{Org: "ab", Kind: "c", Subject: "d"})
|
|
b := alertLockKey(alert.Key{Org: "a", Kind: "bc", Subject: "d"})
|
|
if a == b {
|
|
t.Errorf("keys with shifted field boundaries collide: %q", a)
|
|
}
|
|
}
|