(t *testing.T)
| 551 | } |
| 552 | |
| 553 | func Test_CreateOperations(t *testing.T) { |
| 554 | const ( |
| 555 | namespace = "default" |
| 556 | existingName = "testcm" |
| 557 | existingConfigMap = ` |
| 558 | apiVersion: v1 |
| 559 | kind: ConfigMap |
| 560 | metadata: |
| 561 | namespace: default |
| 562 | name: testcm |
| 563 | data: |
| 564 | foo: "bar" |
| 565 | ` |
| 566 | newName = "newtestcm" |
| 567 | newConfigMap = ` |
| 568 | apiVersion: v1 |
| 569 | kind: ConfigMap |
| 570 | metadata: |
| 571 | namespace: default |
| 572 | name: newtestcm |
| 573 | data: |
| 574 | foo: "bar" |
| 575 | ` |
| 576 | shouldNotCreateNew = false |
| 577 | shouldCreateNew = true |
| 578 | shouldNotBeError = false |
| 579 | shouldBeError = true |
| 580 | ) |
| 581 | |
| 582 | tests := []struct { |
| 583 | name string |
| 584 | fn func(patcher *ObjectPatcher) error |
| 585 | expectNewExists bool |
| 586 | expectError bool |
| 587 | }{ |
| 588 | { |
| 589 | "create new object", |
| 590 | func(patcher *ObjectPatcher) error { |
| 591 | obj := manifest.MustFromYAML(newConfigMap).Unstructured() |
| 592 | return patcher.ExecuteOperation(NewCreateOperation(obj)) |
| 593 | }, |
| 594 | shouldCreateNew, |
| 595 | shouldNotBeError, |
| 596 | }, |
| 597 | { |
| 598 | "create new object ignore existing object", |
| 599 | func(patcher *ObjectPatcher) error { |
| 600 | obj := manifest.MustFromYAML(newConfigMap).Unstructured() |
| 601 | return patcher.ExecuteOperation(NewCreateIfNotExistsOperation(obj)) |
| 602 | }, |
| 603 | shouldCreateNew, |
| 604 | shouldNotBeError, |
| 605 | }, |
| 606 | { |
| 607 | "create existing object", |
| 608 | func(patcher *ObjectPatcher) error { |
| 609 | obj := manifest.MustFromYAML(existingConfigMap).Unstructured() |
| 610 | return patcher.ExecuteOperation(NewCreateOperation(obj)) |
nothing calls this directly
no test coverage detected