(t *testing.T)
| 394 | } |
| 395 | |
| 396 | func 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 | } |
nothing calls this directly
no test coverage detected