Skip to content

Commit

Permalink
review: fix workflow context in commitment cleanup test
Browse files Browse the repository at this point in the history
  • Loading branch information
Varsius committed Feb 25, 2025
1 parent 426294b commit ade90c3
Showing 1 changed file with 20 additions and 19 deletions.
39 changes: 20 additions & 19 deletions internal/collector/commitment_cleanup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ func TestCleanupOldCommitmentsJob(t *testing.T) {
ConfirmedAt: pointerTo(s.Clock.Now()),
ExpiresAt: commitmentForThreeYears.AddTo(s.Clock.Now()),
State: db.CommitmentStateActive,
CreationContextJSON: buf,
CreationContextJSON: json.RawMessage(buf),
}))

// test 1: create an expired commitment
Expand All @@ -98,7 +98,7 @@ func TestCleanupOldCommitmentsJob(t *testing.T) {
ConfirmedAt: pointerTo(s.Clock.Now().Add(-oneDay)),
ExpiresAt: s.Clock.Now(),
State: db.CommitmentStateActive,
CreationContextJSON: buf,
CreationContextJSON: json.RawMessage(buf),
}))
tr.DBChanges().Ignore()

Expand All @@ -117,24 +117,25 @@ func TestCleanupOldCommitmentsJob(t *testing.T) {

// test 2: simulate a commitment that was created yesterday,
// and then moved to a different project five minutes later
creationContext = db.CommitmentWorkflowContext{Reason: db.CommitmentReasonSplit, RelatedCommitmentIDs: []db.ProjectCommitmentID{4}}
creationContext = db.CommitmentWorkflowContext{Reason: db.CommitmentReasonCreate}
buf, err = json.Marshal(creationContext)
mustT(t, err)
supersedeContext := db.CommitmentWorkflowContext{Reason: db.CommitmentReasonSplit, RelatedCommitmentIDs: []db.ProjectCommitmentID{4}}
supersedeBuf, err := json.Marshal(supersedeContext)
mustT(t, err)
mustT(t, c.DB.Insert(&db.ProjectCommitment{
ID: 3,
AZResourceID: 1,
Amount: 10,
Duration: commitmentForOneDay,
CreatedAt: s.Clock.Now().Add(-oneDay),
ConfirmedAt: pointerTo(s.Clock.Now().Add(-oneDay)),
ExpiresAt: s.Clock.Now(),
SupersededAt: pointerTo(s.Clock.Now().Add(-oneDay).Add(5 * time.Minute)),
State: db.CommitmentStateSuperseded,
CreationContextJSON: buf,
ID: 3,
AZResourceID: 1,
Amount: 10,
Duration: commitmentForOneDay,
CreatedAt: s.Clock.Now().Add(-oneDay),
ConfirmedAt: pointerTo(s.Clock.Now().Add(-oneDay)),
ExpiresAt: s.Clock.Now(),
SupersededAt: pointerTo(s.Clock.Now().Add(-oneDay).Add(5 * time.Minute)),
State: db.CommitmentStateSuperseded,
CreationContextJSON: json.RawMessage(buf),
SupersedeContextJSON: pointerTo(json.RawMessage(supersedeBuf)),
}))
creationContext = db.CommitmentWorkflowContext{Reason: db.CommitmentReasonCreate}
buf, err = json.Marshal(creationContext)
mustT(t, err)
mustT(t, c.DB.Insert(&db.ProjectCommitment{
ID: 4,
AZResourceID: 2,
Expand All @@ -144,7 +145,7 @@ func TestCleanupOldCommitmentsJob(t *testing.T) {
ConfirmedAt: pointerTo(s.Clock.Now().Add(-oneDay)),
ExpiresAt: s.Clock.Now(),
State: db.CommitmentStateActive,
CreationContextJSON: buf,
CreationContextJSON: json.RawMessage(buf),
}))
tr.DBChanges().Ignore()

Expand Down Expand Up @@ -174,7 +175,7 @@ func TestCleanupOldCommitmentsJob(t *testing.T) {
ExpiresAt: s.Clock.Now(),
SupersededAt: pointerTo(s.Clock.Now().Add(-oneDay).Add(10 * time.Minute)),
State: db.CommitmentStateSuperseded,
CreationContextJSON: buf,
CreationContextJSON: json.RawMessage(buf),
}
mustT(t, c.DB.Insert(&commitment5))
commitment6 := db.ProjectCommitment{
Expand Down Expand Up @@ -202,7 +203,7 @@ func TestCleanupOldCommitmentsJob(t *testing.T) {
ConfirmedAt: pointerTo(s.Clock.Now().Add(-oneDay).Add(10 * time.Minute)),
ExpiresAt: s.Clock.Now().Add(5 * time.Minute),
State: db.CommitmentStateActive,
CreationContextJSON: buf,
CreationContextJSON: json.RawMessage(buf),
}))
tr.DBChanges().Ignore()

Expand Down

0 comments on commit ade90c3

Please sign in to comment.