cdf17d904d
F1: tolerate up to 3 consecutive health-gate inspect failures (reset on success) before declaring an update failed, so a transient Docker API blip no longer triggers a false rollback. F2: detect baseCtx cancellation during the gate and abort without rolling back or emitting update-failed (debug log only), instead of a misleading "rollback failed" event on every shutdown mid-gate. F3: derive the gate deadline as start + max(RollbackTimeout, StartPeriod+buffer) via effectiveRollbackDeadline, reading the container's healthcheck StartPeriod so a legitimately slow-starting container is not rolled back while starting. F4: only enable the gate when the original reference is a proper tag (new isTagReference helper); skip with a log line for digest-pinned / bare-image-id containers that cannot be re-tagged. F5: document the sequential-tick delay limitation of the gate poll. F6: emit EventUpdated only after the gate confirms healthy (or immediately when no gate is active); the rollback path emits only EventRollback, so the event sequence is truthful. F7: floor RollbackTimeout at 10s in backend and frontend validation. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
89 lines
3.0 KiB
Go
89 lines
3.0 KiB
Go
package settings
|
|
|
|
import (
|
|
"net/http/httptest"
|
|
"testing"
|
|
)
|
|
|
|
func strptr(s string) *string { return &s }
|
|
|
|
// TestSettingsUpdatePayloadValidateAutoUpdatePollInterval covers the auto-update
|
|
// poll-interval floor (F3): durations below minAutoUpdatePollInterval (1m), as
|
|
// well as malformed or non-positive durations, must be rejected.
|
|
func TestSettingsUpdatePayloadValidateAutoUpdatePollInterval(t *testing.T) {
|
|
cases := []struct {
|
|
name string
|
|
interval string
|
|
wantErr bool
|
|
}{
|
|
{name: "one second is below the floor", interval: "1s", wantErr: true},
|
|
{name: "fifty-nine seconds is below the floor", interval: "59s", wantErr: true},
|
|
{name: "exactly one minute is allowed", interval: "1m", wantErr: false},
|
|
{name: "six hours is allowed", interval: "6h", wantErr: false},
|
|
{name: "zero is rejected", interval: "0s", wantErr: true},
|
|
{name: "negative is rejected", interval: "-5m", wantErr: true},
|
|
{name: "unparseable is rejected", interval: "soon", wantErr: true},
|
|
}
|
|
|
|
for _, tc := range cases {
|
|
t.Run(tc.name, func(t *testing.T) {
|
|
payload := settingsUpdatePayload{
|
|
ContainerAutomation: &containerAutomationSettingsPayload{
|
|
AutoUpdate: &autoUpdateSettingsPayload{
|
|
PollInterval: strptr(tc.interval),
|
|
},
|
|
},
|
|
}
|
|
|
|
err := payload.Validate(httptest.NewRequest("PUT", "/settings", nil))
|
|
if tc.wantErr && err == nil {
|
|
t.Errorf("Validate(%q) = nil, want error", tc.interval)
|
|
}
|
|
if !tc.wantErr && err != nil {
|
|
t.Errorf("Validate(%q) = %v, want nil", tc.interval, err)
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|
|
// TestSettingsUpdatePayloadValidateRollbackTimeout covers the M5 health-gated
|
|
// rollback timeout and its floor (F7): it must be a Go duration of at least
|
|
// minAutoUpdateRollbackTimeout (10s), rejecting near-zero, non-positive and
|
|
// malformed values.
|
|
func TestSettingsUpdatePayloadValidateRollbackTimeout(t *testing.T) {
|
|
cases := []struct {
|
|
name string
|
|
timeout string
|
|
wantErr bool
|
|
}{
|
|
{name: "two minutes is allowed", timeout: "120s", wantErr: false},
|
|
{name: "compound duration is allowed", timeout: "1m30s", wantErr: false},
|
|
{name: "exactly the floor is allowed", timeout: "10s", wantErr: false},
|
|
{name: "one millisecond is below the floor", timeout: "1ms", wantErr: true},
|
|
{name: "nine seconds is below the floor", timeout: "9s", wantErr: true},
|
|
{name: "zero is rejected", timeout: "0s", wantErr: true},
|
|
{name: "negative is rejected", timeout: "-5s", wantErr: true},
|
|
{name: "unparseable is rejected", timeout: "soon", wantErr: true},
|
|
}
|
|
|
|
for _, tc := range cases {
|
|
t.Run(tc.name, func(t *testing.T) {
|
|
payload := settingsUpdatePayload{
|
|
ContainerAutomation: &containerAutomationSettingsPayload{
|
|
AutoUpdate: &autoUpdateSettingsPayload{
|
|
RollbackTimeout: strptr(tc.timeout),
|
|
},
|
|
},
|
|
}
|
|
|
|
err := payload.Validate(httptest.NewRequest("PUT", "/settings", nil))
|
|
if tc.wantErr && err == nil {
|
|
t.Errorf("Validate(%q) = nil, want error", tc.timeout)
|
|
}
|
|
if !tc.wantErr && err != nil {
|
|
t.Errorf("Validate(%q) = %v, want nil", tc.timeout, err)
|
|
}
|
|
})
|
|
}
|
|
}
|