|
30 | 30 | _P = fieldpath.MakePathOrDie |
31 | 31 | ) |
32 | 32 |
|
33 | | -func TestManagersDifference(t *testing.T) { |
| 33 | +func TestManagersEquals(t *testing.T) { |
34 | 34 | tests := []struct { |
35 | 35 | name string |
36 | 36 | lhs fieldpath.ManagedFields |
@@ -164,3 +164,123 @@ func TestManagersDifference(t *testing.T) { |
164 | 164 | }) |
165 | 165 | } |
166 | 166 | } |
| 167 | + |
| 168 | +func TestManagersDifference(t *testing.T) { |
| 169 | + tests := []struct { |
| 170 | + name string |
| 171 | + lhs fieldpath.ManagedFields |
| 172 | + rhs fieldpath.ManagedFields |
| 173 | + equal bool |
| 174 | + }{ |
| 175 | + { |
| 176 | + name: "Empty sets", |
| 177 | + equal: true, |
| 178 | + }, |
| 179 | + { |
| 180 | + name: "Same everything", |
| 181 | + lhs: fieldpath.ManagedFields{ |
| 182 | + "one": fieldpath.NewVersionedSet( |
| 183 | + _NS(_P("numeric"), _P("string"), _P("bool")), |
| 184 | + "v1", |
| 185 | + false, |
| 186 | + ), |
| 187 | + }, |
| 188 | + rhs: fieldpath.ManagedFields{ |
| 189 | + "one": fieldpath.NewVersionedSet( |
| 190 | + _NS(_P("numeric"), _P("string"), _P("bool")), |
| 191 | + "v1", |
| 192 | + false, |
| 193 | + ), |
| 194 | + }, |
| 195 | + equal: true, |
| 196 | + }, |
| 197 | + { |
| 198 | + name: "Empty RHS", |
| 199 | + lhs: fieldpath.ManagedFields{ |
| 200 | + "default": fieldpath.NewVersionedSet( |
| 201 | + _NS(_P("numeric"), _P("string"), _P("bool")), |
| 202 | + "v1", |
| 203 | + false, |
| 204 | + ), |
| 205 | + }, |
| 206 | + equal: false, |
| 207 | + }, |
| 208 | + { |
| 209 | + name: "Empty LHS", |
| 210 | + rhs: fieldpath.ManagedFields{ |
| 211 | + "default": fieldpath.NewVersionedSet( |
| 212 | + _NS(_P("numeric"), _P("string"), _P("bool")), |
| 213 | + "v1", |
| 214 | + false, |
| 215 | + ), |
| 216 | + }, |
| 217 | + equal: false, |
| 218 | + }, |
| 219 | + { |
| 220 | + name: "Different managers", |
| 221 | + lhs: fieldpath.ManagedFields{ |
| 222 | + "one": fieldpath.NewVersionedSet( |
| 223 | + _NS(_P("numeric"), _P("string"), _P("bool")), |
| 224 | + "v1", |
| 225 | + false, |
| 226 | + ), |
| 227 | + }, |
| 228 | + rhs: fieldpath.ManagedFields{ |
| 229 | + "two": fieldpath.NewVersionedSet( |
| 230 | + _NS(_P("numeric"), _P("string"), _P("bool")), |
| 231 | + "v1", |
| 232 | + false, |
| 233 | + ), |
| 234 | + }, |
| 235 | + equal: false, |
| 236 | + }, |
| 237 | + { |
| 238 | + name: "Same manager, different version", |
| 239 | + lhs: fieldpath.ManagedFields{ |
| 240 | + "one": fieldpath.NewVersionedSet( |
| 241 | + _NS(_P("numeric"), _P("string"), _P("integer")), |
| 242 | + "v1", |
| 243 | + false, |
| 244 | + ), |
| 245 | + }, |
| 246 | + rhs: fieldpath.ManagedFields{ |
| 247 | + "one": fieldpath.NewVersionedSet( |
| 248 | + _NS(_P("numeric"), _P("string"), _P("bool")), |
| 249 | + "v2", |
| 250 | + false, |
| 251 | + ), |
| 252 | + }, |
| 253 | + equal: false, |
| 254 | + }, |
| 255 | + { |
| 256 | + name: "Set difference", |
| 257 | + lhs: fieldpath.ManagedFields{ |
| 258 | + "one": fieldpath.NewVersionedSet( |
| 259 | + _NS(_P("numeric"), _P("string")), |
| 260 | + "v1", |
| 261 | + false, |
| 262 | + ), |
| 263 | + }, |
| 264 | + rhs: fieldpath.ManagedFields{ |
| 265 | + "one": fieldpath.NewVersionedSet( |
| 266 | + _NS(_P("string"), _P("bool")), |
| 267 | + "v1", |
| 268 | + false, |
| 269 | + ), |
| 270 | + }, |
| 271 | + equal: false, |
| 272 | + }, |
| 273 | + } |
| 274 | + |
| 275 | + for _, test := range tests { |
| 276 | + t.Run(fmt.Sprintf(test.name), func(t *testing.T) { |
| 277 | + equal := test.lhs.Equals(test.rhs) |
| 278 | + if test.equal && !equal { |
| 279 | + difference := test.lhs.Difference(test.rhs) |
| 280 | + t.Errorf("should be equal, but are different: %v", difference) |
| 281 | + } else if !test.equal && equal { |
| 282 | + t.Errorf("should not be equal, but they are") |
| 283 | + } |
| 284 | + }) |
| 285 | + } |
| 286 | +} |
0 commit comments