|
17 | 17 | // |
18 | 18 | // Copyright holder is ArangoDB GmbH, Cologne, Germany |
19 | 19 | // |
20 | | -// Author Ewout Prangsma |
21 | | -// |
22 | 20 |
|
23 | 21 | package v1 |
24 | 22 |
|
25 | 23 | import ( |
26 | 24 | "testing" |
27 | 25 |
|
28 | | - "github.com/arangodb/kube-arangodb/pkg/util" |
29 | 26 | "github.com/stretchr/testify/assert" |
30 | 27 | v1 "k8s.io/api/core/v1" |
| 28 | + |
| 29 | + "github.com/arangodb/kube-arangodb/pkg/backup/utils" |
| 30 | + "github.com/arangodb/kube-arangodb/pkg/util" |
31 | 31 | ) |
32 | 32 |
|
33 | 33 | func TestDeploymentSpecValidate(t *testing.T) { |
@@ -122,3 +122,80 @@ func TestDeploymentSpecResetImmutableFields(t *testing.T) { |
122 | 122 | assert.Equal(t, test.Expected, test.Target) |
123 | 123 | } |
124 | 124 | } |
| 125 | + |
| 126 | +func TestDeploymentSpec_GetCoreContainers(t *testing.T) { |
| 127 | + type fields struct { |
| 128 | + Single ServerGroupSpec |
| 129 | + Agents ServerGroupSpec |
| 130 | + DBServers ServerGroupSpec |
| 131 | + Coordinators ServerGroupSpec |
| 132 | + SyncMasters ServerGroupSpec |
| 133 | + SyncWorkers ServerGroupSpec |
| 134 | + } |
| 135 | + |
| 136 | + type args struct { |
| 137 | + group ServerGroup |
| 138 | + } |
| 139 | + |
| 140 | + tests := map[string]struct { |
| 141 | + fields fields |
| 142 | + args args |
| 143 | + want utils.StringList |
| 144 | + }{ |
| 145 | + "one sidecar container": { |
| 146 | + fields: fields{ |
| 147 | + DBServers: ServerGroupSpec{ |
| 148 | + SidecarCoreNames: []string{"other"}, |
| 149 | + }, |
| 150 | + }, |
| 151 | + args: args{ |
| 152 | + group: ServerGroupDBServers, |
| 153 | + }, |
| 154 | + want: utils.StringList{"server", "other"}, |
| 155 | + }, |
| 156 | + "one predefined container and one sidecar container": { |
| 157 | + fields: fields{ |
| 158 | + DBServers: ServerGroupSpec{ |
| 159 | + SidecarCoreNames: []string{"server", "other"}, |
| 160 | + }, |
| 161 | + }, |
| 162 | + args: args{ |
| 163 | + group: ServerGroupDBServers, |
| 164 | + }, |
| 165 | + want: utils.StringList{"server", "other"}, |
| 166 | + }, |
| 167 | + "zero core containers": { |
| 168 | + fields: fields{ |
| 169 | + DBServers: ServerGroupSpec{ |
| 170 | + SidecarCoreNames: nil, |
| 171 | + }, |
| 172 | + }, |
| 173 | + args: args{ |
| 174 | + group: ServerGroupDBServers, |
| 175 | + }, |
| 176 | + want: utils.StringList{"server"}, |
| 177 | + }, |
| 178 | + "two non-core containers": { |
| 179 | + fields: fields{ |
| 180 | + DBServers: ServerGroupSpec{ |
| 181 | + SidecarCoreNames: []string{"other1", "other2"}, |
| 182 | + }, |
| 183 | + }, |
| 184 | + args: args{ |
| 185 | + group: ServerGroupDBServers, |
| 186 | + }, |
| 187 | + want: utils.StringList{"server", "other1", "other2"}, |
| 188 | + }, |
| 189 | + } |
| 190 | + for testName, test := range tests { |
| 191 | + t.Run(testName, func(t *testing.T) { |
| 192 | + s := DeploymentSpec{ |
| 193 | + DBServers: test.fields.DBServers, |
| 194 | + } |
| 195 | + |
| 196 | + got := s.GetCoreContainers(test.args.group) |
| 197 | + assert.Equal(t, test.want, got) |
| 198 | + |
| 199 | + }) |
| 200 | + } |
| 201 | +} |
0 commit comments