(t *testing.T)
| 375 | } |
| 376 | |
| 377 | func TestCheckOutputDirectoryIsEmpty(t *testing.T) { |
| 378 | t.Run("it returns true if the directory is empty", func(t *testing.T) { |
| 379 | tempDIR := t.TempDir() |
| 380 | |
| 381 | isEmpty := checkOutputDirectoryIsEmpty(&cli{}, &cobra.Command{}, tempDIR) |
| 382 | assert.True(t, isEmpty) |
| 383 | }) |
| 384 | |
| 385 | t.Run("it returns true if the directory doesn't exist", func(t *testing.T) { |
| 386 | isEmpty := checkOutputDirectoryIsEmpty(&cli{}, &cobra.Command{}, "") |
| 387 | assert.True(t, isEmpty) |
| 388 | }) |
| 389 | |
| 390 | t.Run("it returns true if the directory is not empty but we're forcing the command", func(t *testing.T) { |
| 391 | tempDIR := t.TempDir() |
| 392 | files := []string{"auth0_main.tf", "auth0_import.tf", "auth0_generated.tf"} |
| 393 | |
| 394 | for _, file := range files { |
| 395 | filePath := path.Join(tempDIR, file) |
| 396 | _, err := os.Create(filePath) |
| 397 | require.NoError(t, err) |
| 398 | } |
| 399 | |
| 400 | stdout := &bytes.Buffer{} |
| 401 | cli := &cli{ |
| 402 | renderer: &display.Renderer{ |
| 403 | MessageWriter: stdout, |
| 404 | ResultWriter: stdout, |
| 405 | }, |
| 406 | force: true, |
| 407 | noInput: true, |
| 408 | } |
| 409 | |
| 410 | isEmpty := checkOutputDirectoryIsEmpty(cli, &cobra.Command{}, tempDIR) |
| 411 | assert.True(t, isEmpty) |
| 412 | assert.Contains(t, stdout.String(), "Proceeding will overwrite the auth0_main.tf, auth0_import.tf and auth0_generated.tf files.") |
| 413 | }) |
| 414 | } |
| 415 | |
| 416 | func TestCleanOutputDirectory(t *testing.T) { |
| 417 | t.Run("it can successfully clean the output directory from all generated files", func(t *testing.T) { |
nothing calls this directly
no test coverage detected