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

Function TestCmdExport

internal/cmdexport/cmdexport_test.go:396–440  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

394}
395
396func TestCmdExport(t *testing.T) {
397 for i := range testCases {
398 testCase := testCases[i]
399 tempDir, err := setupTempDir(testCase.files)
400 assert.NilError(t, err)
401 err = os.Chdir(tempDir)
402 assert.NilError(t, err)
403
404 err = testCase.ReplaceDIRMacro()
405 assert.NilError(t, err)
406
407 t.Run(testCase.description, func(t *testing.T) {
408
409 r := GetExportRunner()
410 r.Command.SetArgs(testCase.params)
411
412 b := &bytes.Buffer{}
413 // out will be overridden during execution if OutputFilePath is present.
414 r.Command.SetOut(b)
415
416 err := r.Command.Execute()
417
418 if testCase.err != "" {
419 expectedError := strings.TrimLeft(testCase.err, "\n")
420 assert.Error(t, err, expectedError)
421 } else {
422 assert.NilError(t, err)
423
424 expected := strings.TrimLeft(testCase.expected, "\n")
425 var actual string
426 if r.OutputFilePath == "" {
427 actual = b.String()
428 } else {
429 content, _ := ioutil.ReadFile(r.OutputFilePath)
430
431 actual = string(content)
432 }
433
434 assert.Equal(t, expected, actual)
435 }
436 })
437
438 _ = os.RemoveAll(tempDir)
439 }
440}

Callers

nothing calls this directly

Calls 7

setupTempDirFunction · 0.85
GetExportRunnerFunction · 0.85
ReplaceDIRMacroMethod · 0.80
RunMethod · 0.45
ErrorMethod · 0.45
StringMethod · 0.45
RemoveAllMethod · 0.45

Tested by

no test coverage detected