| index e404832ff..a84822520 100644 |
| --- a/internal/hostclaim/create_test.go |
| +++ b/internal/hostclaim/create_test.go |
| @@ -1,6 +1,7 @@ |
| package hostclaim |
| |
| import ( |
| + "bytes" |
| "context" |
| "errors" |
| "testing" |
| @@ -113,3 +114,57 @@ func TestCancelRetiresAndRefusesReuse(t *testing.T) { |
| t.Fatalf("reuse = %v, want ErrRetiredIncarnation", err) |
| } |
| } |
| + |
| +func TestCancelCreateRefusesExecutionAuthority(t *testing.T) { |
| + for _, tc := range []struct { |
| + name string |
| + exec string |
| + participants []string |
| + stamp uint64 |
| + }{ |
| + {name: "executor", exec: "adi-knitting"}, |
| + {name: "participants", participants: []string{"adi-knitting"}}, |
| + {name: "stamp", stamp: 1}, |
| + {name: "all", exec: "adi-knitting", participants: []string{"adi-knitting"}, stamp: 1}, |
| + } { |
| + t.Run(tc.name, func(t *testing.T) { |
| + ctx := context.Background() |
| + s := release.NewDirStore(t.TempDir()) |
| + now := time.Date(2026, 10, 4, 1, 0, 1, 0, time.UTC) |
| + reg, err := Read(ctx, s, testHost) |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + o, err := Update(ctx, s, reg, func(c *Claim) error { |
| + if err := BeginCreate(newHolder(), record, "op_c1", "console", now)(c); err != nil { |
| + return err |
| + } |
| + c.Op.Exec = tc.exec |
| + c.Op.Participants = tc.participants |
| + c.Holder.Stamp = tc.stamp |
| + return nil |
| + }) |
| + if err != nil { |
| + t.Fatalf("store creating claim with authority: %v", err) |
| + } |
| + key, err := Key(testHost) |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + before, beforeETag, err := s.Get(ctx, key) |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + if _, err := Update(ctx, s, o, CancelCreate("op_c1", now)); !errors.Is(err, ErrWrongState) { |
| + t.Errorf("cancel with authority = %v, want ErrWrongState", err) |
| + } |
| + after, afterETag, err := s.Get(ctx, key) |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + if !bytes.Equal(before, after) || beforeETag != afterETag { |
| + t.Errorf("cancel changed stored claim: before ETag %q, after ETag %q", beforeETag, afterETag) |
| + } |
| + }) |
| + } |
| +} |