|
5 | 5 |
|
6 | 6 | troubleshootv1beta2 "github.com/replicatedhq/troubleshoot/pkg/apis/troubleshoot/v1beta2" |
7 | 7 | "github.com/replicatedhq/troubleshoot/pkg/multitype" |
| 8 | + "github.com/stretchr/testify/assert" |
8 | 9 | "github.com/stretchr/testify/require" |
9 | 10 | ) |
10 | 11 |
|
@@ -364,3 +365,83 @@ pwd=somethinggoeshere;`, |
364 | 365 | }) |
365 | 366 | } |
366 | 367 | } |
| 368 | + |
| 369 | +func TestCollector_DedupCollectors(t *testing.T) { |
| 370 | + tests := []struct { |
| 371 | + name string |
| 372 | + Collectors []*troubleshootv1beta2.Collect |
| 373 | + want []*troubleshootv1beta2.Collect |
| 374 | + }{ |
| 375 | + { |
| 376 | + name: "multiple cluster info", |
| 377 | + Collectors: []*troubleshootv1beta2.Collect{ |
| 378 | + { |
| 379 | + ClusterInfo: &troubleshootv1beta2.ClusterInfo{}, |
| 380 | + }, |
| 381 | + { |
| 382 | + ClusterInfo: &troubleshootv1beta2.ClusterInfo{}, |
| 383 | + }, |
| 384 | + }, |
| 385 | + want: []*troubleshootv1beta2.Collect{ |
| 386 | + { |
| 387 | + ClusterInfo: &troubleshootv1beta2.ClusterInfo{}, |
| 388 | + }, |
| 389 | + }, |
| 390 | + }, |
| 391 | + { |
| 392 | + name: "multiple cluster resources with matching namespace lists", |
| 393 | + Collectors: []*troubleshootv1beta2.Collect{ |
| 394 | + { |
| 395 | + ClusterResources: &troubleshootv1beta2.ClusterResources{ |
| 396 | + Namespaces: []string{"namespace1", "namespace2"}, |
| 397 | + }, |
| 398 | + }, |
| 399 | + { |
| 400 | + ClusterResources: &troubleshootv1beta2.ClusterResources{ |
| 401 | + Namespaces: []string{"namespace1", "namespace2"}, |
| 402 | + }, |
| 403 | + }, |
| 404 | + }, |
| 405 | + want: []*troubleshootv1beta2.Collect{ |
| 406 | + { |
| 407 | + ClusterResources: &troubleshootv1beta2.ClusterResources{ |
| 408 | + Namespaces: []string{"namespace1", "namespace2"}, |
| 409 | + }, |
| 410 | + }, |
| 411 | + }, |
| 412 | + }, |
| 413 | + { |
| 414 | + name: "multiple cluster resources with unnique namespace lists", |
| 415 | + Collectors: []*troubleshootv1beta2.Collect{ |
| 416 | + { |
| 417 | + ClusterResources: &troubleshootv1beta2.ClusterResources{ |
| 418 | + Namespaces: []string{"namespace1", "namespace2"}, |
| 419 | + }, |
| 420 | + }, |
| 421 | + { |
| 422 | + ClusterResources: &troubleshootv1beta2.ClusterResources{ |
| 423 | + Namespaces: []string{"namespace1000", "namespace2000"}, |
| 424 | + }, |
| 425 | + }, |
| 426 | + }, |
| 427 | + want: []*troubleshootv1beta2.Collect{ |
| 428 | + { |
| 429 | + ClusterResources: &troubleshootv1beta2.ClusterResources{ |
| 430 | + Namespaces: []string{"namespace1", "namespace2"}, |
| 431 | + }, |
| 432 | + }, |
| 433 | + { |
| 434 | + ClusterResources: &troubleshootv1beta2.ClusterResources{ |
| 435 | + Namespaces: []string{"namespace1000", "namespace2000"}, |
| 436 | + }, |
| 437 | + }, |
| 438 | + }, |
| 439 | + }, |
| 440 | + } |
| 441 | + for _, tc := range tests { |
| 442 | + t.Run(tc.name, func(t *testing.T) { |
| 443 | + got := DedupCollectors(tc.Collectors) |
| 444 | + assert.Equal(t, tc.want, got) |
| 445 | + }) |
| 446 | + } |
| 447 | +} |
0 commit comments