Skip to content

Commit 478cfaa

Browse files
committed
add test case
1 parent 662e27b commit 478cfaa

File tree

1 file changed

+74
-0
lines changed

1 file changed

+74
-0
lines changed

kustomize/commands/edit/fix/convert_test.go

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"testing"
99

1010
"github.com/stretchr/testify/assert"
11+
1112
testutils_test "sigs.k8s.io/kustomize/kustomize/v5/commands/internal/testutils"
1213
"sigs.k8s.io/kustomize/kyaml/filesys"
1314
)
@@ -1143,3 +1144,76 @@ metadata:
11431144
a.b.c: SOME_SECRET_NAME_PLACEHOLDER
11441145
`, string(content))
11451146
}
1147+
1148+
func TestFixVarsWithPatch(t *testing.T) {
1149+
kustomization := []byte(`
1150+
apiVersion: kustomize.config.k8s.io/v1beta1
1151+
kind: Kustomization
1152+
1153+
patchesStrategicMerge:
1154+
- patch.yaml
1155+
1156+
vars:
1157+
- name: CERTIFICATE_NAMESPACE
1158+
objref:
1159+
name: system
1160+
fieldref:
1161+
fieldpath: metadata.namespace
1162+
`)
1163+
patch := []byte(`
1164+
apiVersion: apps/v1
1165+
kapiVersion: apps/v1
1166+
kind: Deployment
1167+
metadata:
1168+
name: controller-manager
1169+
namespace: system
1170+
spec:
1171+
template:
1172+
spec:
1173+
containers:
1174+
- name: $(CERTIFICATE_NAMESPACE)
1175+
`)
1176+
1177+
fSys := filesys.MakeFsInMemory()
1178+
testutils_test.WriteTestKustomizationWith(fSys, kustomization)
1179+
fSys.WriteFile("patch.yaml", patch)
1180+
cmd := NewCmdFix(fSys, os.Stdout)
1181+
assert.NoError(t, cmd.Flags().Set("vars", "true"))
1182+
assert.NoError(t, cmd.RunE(cmd, nil))
1183+
content, err := testutils_test.ReadTestKustomization(fSys)
1184+
assert.NoError(t, err)
1185+
1186+
assert.Equal(t, `
1187+
apiVersion: kustomize.config.k8s.io/v1beta1
1188+
kind: Kustomization
1189+
1190+
1191+
patches:
1192+
- path: patch.yaml
1193+
replacements:
1194+
- source:
1195+
fieldPath: metadata.namespace
1196+
name: system
1197+
targets:
1198+
- fieldPaths:
1199+
- spec.template.spec.containers.0.name
1200+
select:
1201+
namespace: system
1202+
`, string(content))
1203+
1204+
content, err = fSys.ReadFile("patch.yaml")
1205+
assert.NoError(t, err)
1206+
assert.Equal(t, `
1207+
apiVersion: apps/v1
1208+
kapiVersion: apps/v1
1209+
kind: Deployment
1210+
metadata:
1211+
name: controller-manager
1212+
namespace: system
1213+
spec:
1214+
template:
1215+
spec:
1216+
containers:
1217+
- name: CERTIFICATE_NAMESPACE_PLACEHOLDER
1218+
`, string(content))
1219+
}

0 commit comments

Comments
 (0)