MCPcopy Create free account
hub / github.com/flant/shell-operator / Test_CreateOperations

Function Test_CreateOperations

pkg/kube/object_patch/patch_test.go:553–800  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

551}
552
553func Test_CreateOperations(t *testing.T) {
554 const (
555 namespace = "default"
556 existingName = "testcm"
557 existingConfigMap = `
558apiVersion: v1
559kind: ConfigMap
560metadata:
561 namespace: default
562 name: testcm
563data:
564 foo: "bar"
565`
566 newName = "newtestcm"
567 newConfigMap = `
568apiVersion: v1
569kind: ConfigMap
570metadata:
571 namespace: default
572 name: newtestcm
573data:
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))

Callers

nothing calls this directly

Calls 10

ExecuteOperationMethod · 0.95
ExecuteOperationsMethod · 0.95
NewCreateOperationFunction · 0.85
ParseOperationsFunction · 0.85
NewObjectPatcherFunction · 0.85
existObjectFunction · 0.85
RunMethod · 0.45
ErrorMethod · 0.45

Tested by

no test coverage detected