mirror of
https://github.com/kubernetes-sigs/kustomize.git
synced 2026-06-29 17:41:13 +00:00
feat: add remove configmap command
(cherry picked from commit0d7c56dcf8) fix: add logging when configmap not exists (cherry picked from commit0235f10b09) fix: correct lint issues (cherry picked from commit8ca1f3813b) fix: Resolve conversation (cherry picked from commit927804dfe5)
This commit is contained in:
84
kustomize/commands/edit/remove/removeconfigmap_test.go
Normal file
84
kustomize/commands/edit/remove/removeconfigmap_test.go
Normal file
@@ -0,0 +1,84 @@
|
||||
// Copyright 2019 The Kubernetes Authors.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
package remove //nolint:testpackage
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
testutils_test "sigs.k8s.io/kustomize/kustomize/v4/commands/internal/testutils"
|
||||
"sigs.k8s.io/kustomize/kyaml/filesys"
|
||||
)
|
||||
|
||||
func TestRemoveConfigMap(t *testing.T) {
|
||||
const configMapName01 = "example-configmap-01"
|
||||
const configMapName02 = "example-configmap-02"
|
||||
|
||||
tests := map[string]struct {
|
||||
input string
|
||||
args []string
|
||||
expectedErr string
|
||||
}{
|
||||
"happy path": {
|
||||
input: fmt.Sprintf(`
|
||||
apiVersion: kustomize.config.k8s.io/v1beta1
|
||||
kind: Kustomization
|
||||
configMapGenerator:
|
||||
- name: %s
|
||||
files:
|
||||
- application.properties
|
||||
`, configMapName01),
|
||||
args: []string{configMapName01},
|
||||
},
|
||||
"multiple": {
|
||||
input: fmt.Sprintf(`
|
||||
apiVersion: kustomize.config.k8s.io/v1beta1
|
||||
kind: Kustomization
|
||||
configMapGenerator:
|
||||
- name: %s
|
||||
files:
|
||||
- application.properties
|
||||
- name: %s
|
||||
files:
|
||||
- application.properties
|
||||
`, configMapName01, configMapName02),
|
||||
args: []string{
|
||||
fmt.Sprintf("%s,%s", configMapName01, configMapName02),
|
||||
},
|
||||
},
|
||||
"miss": {
|
||||
input: fmt.Sprintf(`
|
||||
apiVersion: kustomize.config.k8s.io/v1beta1
|
||||
kind: Kustomization
|
||||
configMapGenerator:
|
||||
- name: %s
|
||||
files:
|
||||
- application.properties
|
||||
`, configMapName01),
|
||||
args: []string{"foo"},
|
||||
},
|
||||
}
|
||||
|
||||
for name, tc := range tests {
|
||||
t.Run(name, func(t *testing.T) {
|
||||
fSys := filesys.MakeFsInMemory()
|
||||
testutils_test.WriteTestKustomizationWith(fSys, []byte(tc.input))
|
||||
cmd := newCmdRemoveConfigMap(fSys)
|
||||
err := cmd.RunE(cmd, tc.args)
|
||||
if tc.expectedErr != "" {
|
||||
assert.Error(t, err)
|
||||
assert.Contains(t, err.Error(), tc.expectedErr)
|
||||
} else {
|
||||
assert.NoError(t, err)
|
||||
content, err := testutils_test.ReadTestKustomization(fSys)
|
||||
assert.NoError(t, err)
|
||||
for _, opt := range strings.Split(tc.args[0], ",") {
|
||||
assert.NotContains(t, string(content), opt)
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user