| 1 | package relay |
| 2 | |
| 3 | import ( |
| 4 | "context" |
| 5 | "errors" |
| 6 | "testing" |
| 7 | |
| 8 | "github.com/carlosframework/platform/internal/release" |
| 9 | ) |
| 10 | |
| 11 | func TestNewIncarnation(t *testing.T) { |
| 12 | a, b := NewIncarnation(), NewIncarnation() |
| 13 | if !incarnationRe.MatchString(a) || a == b { |
| 14 | t.Fatalf("%q %q", a, b) |
| 15 | } |
| 16 | } |
| 17 | |
| 18 | func TestRecordRoundTrip(t *testing.T) { |
| 19 | s := newMemStore(t) |
| 20 | ctx := context.Background() |
| 21 | r, etag, err := GetRecord(ctx, s, "abc", "meet") |
| 22 | if err != nil || r != nil || etag != "" { |
| 23 | t.Fatalf("absent = %v %q %v", r, etag, err) |
| 24 | } |
| 25 | etag, err = PutRecord(ctx, s, "abc", "meet", &Record{Enabled: true, Incarnation: NewIncarnation(), Op: 1, Phase: "config"}, "") |
| 26 | if err != nil { |
| 27 | t.Fatal(err) |
| 28 | } |
| 29 | if _, err := PutRecord(ctx, s, "abc", "meet", &Record{}, "stale-etag"); !errors.Is(err, release.ErrCASConflict) { |
| 30 | t.Fatalf("stale put = %v, want CAS conflict", err) |
| 31 | } |
| 32 | r, _, _ = GetRecord(ctx, s, "abc", "meet") |
| 33 | if !r.Enabled || r.Op != 1 { |
| 34 | t.Fatalf("record = %+v", r) |
| 35 | } |
| 36 | } |
| 37 | |