|
1 | 1 | package group
|
2 | 2 |
|
3 | 3 | import (
|
| 4 | + "testing" |
| 5 | + "time" |
| 6 | + |
4 | 7 | mock_group "github.com/docker/infrakit/pkg/mock/plugin/group"
|
| 8 | + mock_instance "github.com/docker/infrakit/pkg/mock/spi/instance" |
| 9 | + "github.com/docker/infrakit/pkg/plugin/group/types" |
5 | 10 | "github.com/docker/infrakit/pkg/spi/group"
|
6 | 11 | "github.com/docker/infrakit/pkg/spi/instance"
|
7 | 12 | "github.com/golang/mock/gomock"
|
8 |
| - "testing" |
9 |
| - "time" |
| 13 | + "github.com/stretchr/testify/require" |
10 | 14 | )
|
11 | 15 |
|
12 | 16 | var (
|
@@ -95,3 +99,96 @@ func TestRemoveUnknown(t *testing.T) {
|
95 | 99 |
|
96 | 100 | quorum.Run()
|
97 | 101 | }
|
| 102 | + |
| 103 | +func TestQuorumPlanUpdateNoChanges(t *testing.T) { |
| 104 | + ctrl := gomock.NewController(t) |
| 105 | + defer ctrl.Finish() |
| 106 | + |
| 107 | + groupID := group.ID("quorum") |
| 108 | + scaled := mock_group.NewMockScaled(ctrl) |
| 109 | + instancePlugin := mock_instance.NewMockPlugin(ctrl) |
| 110 | + settings := groupSettings{ |
| 111 | + instancePlugin: instancePlugin, |
| 112 | + config: types.Spec{ |
| 113 | + Allocation: types.AllocationMethod{ |
| 114 | + LogicalIDs: []instance.LogicalID{ |
| 115 | + *a.LogicalID, |
| 116 | + }, |
| 117 | + }, |
| 118 | + }, |
| 119 | + } |
| 120 | + quorum := NewQuorum(groupID, scaled, logicalIDs, 1*time.Millisecond) |
| 121 | + plan, err := quorum.PlanUpdate(scaled, settings, settings) |
| 122 | + require.NoError(t, err) |
| 123 | + require.IsType(t, &noopUpdate{}, plan) |
| 124 | +} |
| 125 | + |
| 126 | +func TestQuorumPlanUpdateLogicalIDChange(t *testing.T) { |
| 127 | + ctrl := gomock.NewController(t) |
| 128 | + defer ctrl.Finish() |
| 129 | + |
| 130 | + groupID := group.ID("quorum") |
| 131 | + scaled := mock_group.NewMockScaled(ctrl) |
| 132 | + instancePlugin := mock_instance.NewMockPlugin(ctrl) |
| 133 | + settingsOld := groupSettings{ |
| 134 | + instancePlugin: instancePlugin, |
| 135 | + config: types.Spec{ |
| 136 | + Allocation: types.AllocationMethod{ |
| 137 | + LogicalIDs: []instance.LogicalID{ |
| 138 | + *a.LogicalID, |
| 139 | + }, |
| 140 | + }, |
| 141 | + }, |
| 142 | + } |
| 143 | + settingsNew := groupSettings{ |
| 144 | + instancePlugin: instancePlugin, |
| 145 | + config: types.Spec{ |
| 146 | + Allocation: types.AllocationMethod{ |
| 147 | + LogicalIDs: []instance.LogicalID{ |
| 148 | + *b.LogicalID, |
| 149 | + }, |
| 150 | + }, |
| 151 | + }, |
| 152 | + } |
| 153 | + quorum := NewQuorum(groupID, scaled, logicalIDs, 1*time.Millisecond) |
| 154 | + _, err := quorum.PlanUpdate(scaled, settingsOld, settingsNew) |
| 155 | + require.Error(t, err) |
| 156 | +} |
| 157 | + |
| 158 | +func TestQuorumPlanUpdateRollingUpdate(t *testing.T) { |
| 159 | + ctrl := gomock.NewController(t) |
| 160 | + defer ctrl.Finish() |
| 161 | + |
| 162 | + groupID := group.ID("quorum") |
| 163 | + scaled := mock_group.NewMockScaled(ctrl) |
| 164 | + instancePlugin := mock_instance.NewMockPlugin(ctrl) |
| 165 | + instanceOld := types.InstancePlugin{ |
| 166 | + Plugin: "name-old", |
| 167 | + } |
| 168 | + instanceNew := types.InstancePlugin{ |
| 169 | + Plugin: "name-new", |
| 170 | + } |
| 171 | + allocation := types.AllocationMethod{ |
| 172 | + LogicalIDs: []instance.LogicalID{ |
| 173 | + *b.LogicalID, |
| 174 | + }, |
| 175 | + } |
| 176 | + settingsOld := groupSettings{ |
| 177 | + instancePlugin: instancePlugin, |
| 178 | + config: types.Spec{ |
| 179 | + Allocation: allocation, |
| 180 | + Instance: instanceOld, |
| 181 | + }, |
| 182 | + } |
| 183 | + settingsNew := groupSettings{ |
| 184 | + instancePlugin: instancePlugin, |
| 185 | + config: types.Spec{ |
| 186 | + Allocation: allocation, |
| 187 | + Instance: instanceNew, |
| 188 | + }, |
| 189 | + } |
| 190 | + quorum := NewQuorum(groupID, scaled, logicalIDs, 1*time.Millisecond) |
| 191 | + plan, err := quorum.PlanUpdate(scaled, settingsOld, settingsNew) |
| 192 | + require.NoError(t, err) |
| 193 | + require.IsType(t, &rollingupdate{}, plan) |
| 194 | +} |
0 commit comments