| 67 | } |
| 68 | |
| 69 | func TestRunRejectsExistingConfigWithoutForce(t *testing.T) { |
| 70 | targetPath := filepath.Join(t.TempDir(), "config.yml") |
| 71 | require.NoError(t, os.WriteFile(targetPath, []byte("existing"), 0600)) |
| 72 | |
| 73 | _, err := Run(Options{ |
| 74 | TargetPath: targetPath, |
| 75 | Prompts: &fakePrompts{ |
| 76 | lines: []string{"user@example.com", "", ""}, |
| 77 | password: "secret", |
| 78 | }, |
| 79 | }) |
| 80 | require.Error(t, err) |
| 81 | assert.Contains(t, err.Error(), "already exists") |
| 82 | |
| 83 | bs, readErr := os.ReadFile(targetPath) |
| 84 | require.NoError(t, readErr) |
| 85 | assert.Equal(t, "existing", string(bs)) |
| 86 | } |
| 87 | |
| 88 | func TestRunOverwritesExistingConfigWithForce(t *testing.T) { |
| 89 | targetPath := filepath.Join(t.TempDir(), "config.yml") |