Skip to content

Commit

Permalink
Unit test for maximum replicas per node
Browse files Browse the repository at this point in the history
Signed-off-by: Olli Janatuinen <[email protected]>
  • Loading branch information
olljanat committed Feb 18, 2019
1 parent 02130d9 commit 79b5119
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
9 changes: 9 additions & 0 deletions cli/command/service/opts_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -224,3 +224,12 @@ func TestToServiceUpdateRollback(t *testing.T) {
assert.Check(t, is.DeepEqual(service.UpdateConfig, expected.UpdateConfig))
assert.Check(t, is.DeepEqual(service.RollbackConfig, expected.RollbackConfig))
}

func TestToServiceMaxReplicasGlobalModeConflict(t *testing.T) {
opt := serviceOptions{
mode: "global",
maxReplicas: 1,
}
_, err := opt.ToServiceMode()
assert.Error(t, err, "replicas-max-per-node can only be used with replicated mode")
}
20 changes: 20 additions & 0 deletions cli/command/service/update_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -808,3 +808,23 @@ func TestUpdateNetworks(t *testing.T) {
assert.NilError(t, err)
assert.Check(t, is.DeepEqual([]swarm.NetworkAttachmentConfig{{Target: "id999"}}, svc.TaskTemplate.Networks))
}

func TestUpdateMaxReplicas(t *testing.T) {
ctx := context.Background()

svc := swarm.ServiceSpec{
TaskTemplate: swarm.TaskSpec{
ContainerSpec: &swarm.ContainerSpec{},
Placement: &swarm.Placement{
MaxReplicas: 1,
},
},
}

flags := newUpdateCommand(nil).Flags()
flags.Set(flagMaxReplicas, "2")
err := updateService(ctx, nil, flags, &svc)
assert.NilError(t, err)

assert.Check(t, is.DeepEqual(svc.TaskTemplate.Placement, &swarm.Placement{MaxReplicas: 0x02}))
}

0 comments on commit 79b5119

Please sign in to comment.