fix: review fixes for webhook and auto mode (#8)
Clear available_* only when the deployed ref equals it, drop the unused poll source, stop leaking internal errors to CI, use the request-scoped logger, validate X-Request-ID, re-read jobs once after the timeout, report refused when no target ref exists, and tidy UI, deploy and docs.
This commit is contained in:
@@ -88,18 +88,20 @@ func TestUpsertKeepsUpdateMode(t *testing.T) {
|
||||
assert.Equal(t, model.ModeAuto, got.UpdateMode)
|
||||
}
|
||||
|
||||
func TestFinishJob_ClearsAvailableOnlyWhenJobIsNewer(t *testing.T) {
|
||||
func TestFinishJob_ClearsAvailableOnlyWhenThatVersionWasDeployed(t *testing.T) {
|
||||
succeed := model.JobFinish{Status: model.JobSucceeded, Ref: "r:2@sha256:d", StartedAt: t0, FinishedAt: t0}
|
||||
tests := []struct {
|
||||
name string
|
||||
availableAt time.Time // job is created at t0
|
||||
finish model.JobFinish
|
||||
wantCleared bool
|
||||
name string
|
||||
availableRef string
|
||||
availableAt time.Time // job is created at t0 for r:2
|
||||
finish model.JobFinish
|
||||
wantCleared bool
|
||||
}{
|
||||
{"suggestion before the job", t0.Add(-time.Minute), succeed, true},
|
||||
{"suggestion at the same instant", t0, succeed, true},
|
||||
{"suggestion after the job was created", t0.Add(time.Minute), succeed, false},
|
||||
{"failed job keeps the suggestion", t0.Add(-time.Minute),
|
||||
{"same ref, suggestion before the job", "r:2", t0.Add(-time.Minute), succeed, true},
|
||||
{"same ref, suggestion at the same instant", "r:2", t0, succeed, true},
|
||||
{"same ref, suggestion after the job was created", "r:2", t0.Add(time.Minute), succeed, false},
|
||||
{"different ref keeps the suggestion", "r:3", t0.Add(-time.Minute), succeed, false},
|
||||
{"failed job keeps the suggestion", "r:2", t0.Add(-time.Minute),
|
||||
model.JobFinish{Status: model.JobFailed, Error: "boom", StartedAt: t0, FinishedAt: t0}, false},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
@@ -107,8 +109,10 @@ func TestFinishJob_ClearsAvailableOnlyWhenJobIsNewer(t *testing.T) {
|
||||
s := openTestStore(t)
|
||||
ctx := context.Background()
|
||||
agent, svc := jobFixture(t, s, "a")
|
||||
require.NoError(t, s.SetAvailable(ctx, svc, model.Available{Ref: "r:2", Source: model.SourceWebhook, At: tt.availableAt}))
|
||||
j, err := s.CreateJob(ctx, newJob(svc, agent))
|
||||
require.NoError(t, s.SetAvailable(ctx, svc, model.Available{Ref: tt.availableRef, Source: model.SourceWebhook, At: tt.availableAt}))
|
||||
nj := newJob(svc, agent)
|
||||
nj.ToRef = "r:2"
|
||||
j, err := s.CreateJob(ctx, nj)
|
||||
require.NoError(t, err)
|
||||
|
||||
ok, err := s.FinishJob(ctx, agent, j.ID, tt.finish)
|
||||
@@ -122,7 +126,7 @@ func TestFinishJob_ClearsAvailableOnlyWhenJobIsNewer(t *testing.T) {
|
||||
assert.Empty(t, got.AvailableSource)
|
||||
assert.Nil(t, got.AvailableAt)
|
||||
} else {
|
||||
assert.Equal(t, "r:2", got.AvailableRef)
|
||||
assert.Equal(t, tt.availableRef, got.AvailableRef)
|
||||
assert.Equal(t, model.SourceWebhook, got.AvailableSource)
|
||||
assert.NotNil(t, got.AvailableAt)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user