package allocaterequest import "testing" func TestRequestIdentity(t *testing.T) { requestID := "alloc_0123456789abcdef" first, err := Key("A", 7, requestID) if err != nil || len(first) != 64 { t.Fatal(first, err) } same, _ := Key("A", 7, requestID) if first != same { t.Fatal("unstable identity") } for _, entry := range []struct { tenant string user int64 id string }{{"B", 7, requestID}, {"A", 8, requestID}, {"A", 7, requestID + "2"}} { other, err := Key(entry.tenant, entry.user, entry.id) if err != nil || other == first { t.Fatal("identity scope collision", err) } } for _, id := range []string{"", "short", "0123456789abcdef/"} { if _, err := Key("A", 7, id); err == nil { t.Fatal("invalid identity accepted", id) } } } func TestFingerprint(t *testing.T) { first := Fingerprint([]string{"B", "A"}, 1, 2, 2, " remark ") if first != Fingerprint([]string{"A", "B"}, 1, 2, 2, "remark") { t.Fatal("card order changed identity") } for _, other := range []string{Fingerprint([]string{"A"}, 1, 2, 2, "remark"), Fingerprint([]string{"A", "B"}, 2, 2, 2, "remark"), Fingerprint([]string{"A", "B"}, 1, 3, 2, "remark"), Fingerprint([]string{"A", "B"}, 1, 2, 1, "remark"), Fingerprint([]string{"A", "B"}, 1, 2, 2, "other")} { if first == other { t.Fatal("changed parameters accepted") } } }