MCPcopy
hub / github.com/kptdev/kpt / TestSearchSubPackages

Function TestSearchSubPackages

internal/cmdsearch/cmdsearch_test.go:126–216  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

124}
125
126func TestSearchSubPackages(t *testing.T) {
127 var tests = []struct {
128 name string
129 dataset string
130 args []string
131 out string
132 errMsg string
133 }{
134 {
135 name: "search-replace-recurse-subpackages",
136 dataset: "dataset-with-autosetters",
137 args: []string{"--by-value", "myspace", "--put-literal", "otherspace"},
138 out: `${baseDir}/mysql/deployment.yaml
139fieldPath: metadata.namespace
140value: otherspace # {"$openapi":"gcloud.core.project"}
141
142${baseDir}/mysql/nosetters/deployment.yaml
143fieldPath: metadata.namespace
144value: otherspace
145
146${baseDir}/mysql/storage/deployment.yaml
147fieldPath: metadata.namespace
148value: otherspace # {"$openapi":"gcloud.core.project"}
149
150Mutated 3 field(s)
151`,
152 },
153 {
154 name: "search-recurse-subpackages",
155 dataset: "dataset-with-autosetters",
156 args: []string{"--by-value", "mysql"},
157 out: `${baseDir}/mysql/deployment.yaml
158fieldPath: spec.template.spec.containers[0].name
159value: mysql
160
161Matched 1 field(s)
162`,
163 },
164 }
165 for i := range tests {
166 test := tests[i]
167 t.Run(test.name, func(t *testing.T) {
168 testDataDir := filepath.Join("../", "testutil", "testdata")
169 fieldmeta.SetShortHandRef("$kpt-set")
170 sourceDir := filepath.Join(testDataDir, test.dataset)
171 baseDir, err := ioutil.TempDir("", "")
172 if !assert.NoError(t, err) {
173 t.FailNow()
174 }
175 err = copyutil.CopyDir(sourceDir, baseDir)
176 if !assert.NoError(t, err) {
177 t.FailNow()
178 }
179 ext.KRMFileName = func() string {
180 return kptfile.KptFileName
181 }
182 defer os.RemoveAll(baseDir)
183 runner := NewSearchRunner("")

Callers

nothing calls this directly

Calls 5

NewSearchRunnerFunction · 0.85
RunMethod · 0.45
RemoveAllMethod · 0.45
ErrorMethod · 0.45
StringMethod · 0.45

Tested by

no test coverage detected