package hostbox import ( "context" "github.com/carlosframework/platform/internal/hostguard" "testing" "time" ) func TestPlan14InventoryCarriesCapturedRevision(t *testing.T) { calls := 0 _, db := RemoteJournals(func(_ context.Context, q JournalRequest) (JournalResponse, error) { calls++ if q.Op != "inventory-write" || q.Revision != 7 || q.RecordKey != "record" || q.RecordETag != "etag" || q.Target.ClaimETag != "claim" { t.Fatalf("uncaptured inventory request: %+v", q) } return JournalResponse{V: 1, ID: q.ID, Revision: 8}, nil }) expected := InventoryExpectation{Revision: 7, RecordKey: "record", RecordETag: "etag", Target: hostguard.FenceTarget{Host: "shop.example", Incarnation: "inc", Stamp: 1, ClaimETag: "claim"}} revision, err := db.WriteExpected(t.Context(), StopInventory{Host: "shop.example", Incarnation: "inc", InstallationStamp: 1}, expected) if err != nil || revision != 8 || calls != 1 { t.Fatalf("inventory commit: %d %d %v", revision, calls, err) } } func TestPlan14InventoryIdentityCoversRecordExpectations(t *testing.T) { q, err := journalPrepare(JournalRequest{Op: "inventory-write", RecordKey: "record", RecordETag: "etag"}, time.Now()) if err != nil { t.Fatal(err) } if q.V != 3 { t.Fatalf("inventory expectations use protocol %d", q.V) } for _, field := range []string{"key", "etag"} { changed := q if field == "key" { changed.RecordKey = "other" } else { changed.RecordETag = "other" } if validateJournalRequest(changed) == nil { t.Fatal("record expectation not bound to request identity") } } q.V = 2 q.ID = journalRequestID(q) if validateJournalRequest(q) == nil { t.Fatal("old protocol accepted unhashed record expectations") } }