fix: address review findings for self-update (#15)
This commit is contained in:
@@ -138,7 +138,7 @@ func TestSnapshot_PlainContainerAndSwarmTaskSkipped(t *testing.T) {
|
||||
func TestSnapshot_SelfUpdateHelperSkipped(t *testing.T) {
|
||||
cli := &fakeDocker{containers: []container.Summary{
|
||||
{ID: "h1", Names: []string{"/quirky_helper"}, Image: "sha256:agentimage", State: "running",
|
||||
Labels: map[string]string{protocol.LabelSelfUpdateJob: "7"}},
|
||||
Labels: map[string]string{labelSelfUpdateJob: "7"}},
|
||||
{ID: "p1", Names: []string{"/adhoc"}, Image: "redis:alpine", State: "exited"},
|
||||
}}
|
||||
got, err := New(cli, "").Snapshot(context.Background())
|
||||
@@ -158,6 +158,63 @@ func TestSnapshot_SelfFlag(t *testing.T) {
|
||||
assert.True(t, got[0].Self)
|
||||
}
|
||||
|
||||
func TestSnapshot_SelfFlagByContainerName(t *testing.T) {
|
||||
cli := &fakeDocker{
|
||||
containers: []container.Summary{
|
||||
composeContainer("0123456789abcdef", "updater-agent", "agent", "pu:1", "sha256:i", "running"),
|
||||
composeContainer("fedcba9876543210", "slusk", "web", "slusk:1", "sha256:j", "running"),
|
||||
},
|
||||
inspect: map[string]container.InspectResponse{
|
||||
"updater-agent-agent-1": {ContainerJSONBase: &container.ContainerJSONBase{ID: "0123456789abcdef"}},
|
||||
},
|
||||
}
|
||||
got, err := New(cli, "updater-agent-agent-1").Snapshot(context.Background())
|
||||
require.NoError(t, err)
|
||||
require.Len(t, got, 2)
|
||||
assert.False(t, got[0].Self, "slusk")
|
||||
assert.True(t, got[1].Self, "updater-agent")
|
||||
}
|
||||
|
||||
func TestSnapshot_SelfFlagFallsBackToIDPrefixWhenInspectFails(t *testing.T) {
|
||||
cli := &fakeDocker{
|
||||
containers: []container.Summary{composeContainer("0123456789abcdef", "updater-agent", "agent", "pu:1", "sha256:i", "running")},
|
||||
inspectErr: errors.New("boom"),
|
||||
}
|
||||
got, err := New(cli, "0123456789ab").Snapshot(context.Background())
|
||||
require.NoError(t, err)
|
||||
require.Len(t, got, 1)
|
||||
assert.True(t, got[0].Self)
|
||||
}
|
||||
|
||||
func TestSnapshot_AgentsOwnSwarmServiceIsSelf(t *testing.T) {
|
||||
swarmSvc := func(name string) swarm.Service {
|
||||
return swarm.Service{
|
||||
Spec: swarm.ServiceSpec{
|
||||
Annotations: swarm.Annotations{Name: name},
|
||||
TaskTemplate: swarm.TaskSpec{ContainerSpec: &swarm.ContainerSpec{Image: "pu:1"}},
|
||||
},
|
||||
ServiceStatus: &swarm.ServiceStatus{RunningTasks: 1, DesiredTasks: 1},
|
||||
}
|
||||
}
|
||||
cli := &fakeDocker{
|
||||
info: managerInfo(),
|
||||
services: []swarm.Service{swarmSvc("pu_agent"), swarmSvc("pu_master")},
|
||||
inspect: map[string]container.InspectResponse{
|
||||
"abc123": {
|
||||
ContainerJSONBase: &container.ContainerJSONBase{ID: "abc123full"},
|
||||
Config: &container.Config{Labels: map[string]string{labelSwarmName: "pu_agent"}},
|
||||
},
|
||||
},
|
||||
}
|
||||
got, err := New(cli, "abc123").Snapshot(context.Background())
|
||||
require.NoError(t, err)
|
||||
require.Len(t, got, 2)
|
||||
assert.Equal(t, "pu_agent", got[0].SwarmService)
|
||||
assert.True(t, got[0].Self)
|
||||
assert.Equal(t, "pu_master", got[1].SwarmService)
|
||||
assert.False(t, got[1].Self)
|
||||
}
|
||||
|
||||
func TestSnapshot_SwarmServicesOnlyOnManager(t *testing.T) {
|
||||
svc := swarm.Service{
|
||||
Spec: swarm.ServiceSpec{
|
||||
|
||||
Reference in New Issue
Block a user