fix: address review findings for self-update (#15)
This commit is contained in:
@@ -16,6 +16,8 @@ import (
|
||||
"github.com/shcizo/package-updater/internal/protocol"
|
||||
)
|
||||
|
||||
const selfImage = "gitea.shcizo.se/shcizo/package-updater:latest"
|
||||
|
||||
type fakeStore struct {
|
||||
services map[int64]model.Service
|
||||
jobs map[int64]model.Job
|
||||
@@ -125,7 +127,7 @@ func ptr[T any](v T) *T { return &v }
|
||||
|
||||
func newService(st *fakeStore, h *fakeHub) (*Service, *fakePub) {
|
||||
pub := &fakePub{}
|
||||
return New(st, h, pub, slog.New(slog.NewTextHandler(io.Discard, nil))), pub
|
||||
return New(st, h, pub, selfImage, slog.New(slog.NewTextHandler(io.Discard, nil))), pub
|
||||
}
|
||||
|
||||
func TestUpdatable(t *testing.T) {
|
||||
@@ -417,6 +419,20 @@ func TestStart_SelfServiceNeedsASelfUpdatingAgent(t *testing.T) {
|
||||
require.Len(t, h.starts, 1)
|
||||
assert.True(t, h.starts[0].start.Self)
|
||||
})
|
||||
t.Run("a service with the agent image repo needs a self-updating agent but is not marked", func(t *testing.T) {
|
||||
svc := composeSvc
|
||||
svc.ActualRef = selfImage
|
||||
st := &fakeStore{services: map[int64]model.Service{1: svc}, jobs: map[int64]model.Job{}}
|
||||
h := &fakeHub{route: ok}
|
||||
s, _ := newService(st, h)
|
||||
|
||||
_, err := s.Start(context.Background(), svc, StartRequest{Trigger: model.TriggerManual})
|
||||
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, []int{protocol.MinSelfUpdateVersion}, h.mins)
|
||||
require.Len(t, h.starts, 1)
|
||||
assert.False(t, h.starts[0].start.Self)
|
||||
})
|
||||
t.Run("a service that is not the agent's own is not marked", func(t *testing.T) {
|
||||
st := &fakeStore{services: map[int64]model.Service{1: composeSvc}, jobs: map[int64]model.Job{}}
|
||||
h := &fakeHub{route: ok}
|
||||
|
||||
Reference in New Issue
Block a user