| 205 | } |
| 206 | |
| 207 | func TestInitCmd_EdgeCases(t *testing.T) { |
| 208 | tests := []struct { |
| 209 | name string |
| 210 | args []string |
| 211 | expectError bool |
| 212 | description string |
| 213 | }{ |
| 214 | { |
| 215 | name: "branch_with_master", |
| 216 | args: []string{"--url=" + test_conf_repo_url, "--branch=master"}, |
| 217 | expectError: false, |
| 218 | description: "Should succeed with existing branch", |
| 219 | }, |
| 220 | { |
| 221 | name: "branch_nonexistent", |
| 222 | args: []string{"--url=" + test_conf_repo_url, "--branch=does-not-exist-9999"}, |
| 223 | expectError: true, |
| 224 | description: "Should fail when branch does not exist on remote", |
| 225 | }, |
| 226 | { |
| 227 | name: "url_not_a_git_repo", |
| 228 | args: []string{"--url=https://example.com/not-a-repo.git"}, |
| 229 | expectError: true, |
| 230 | description: "Should fail when URL is not a real git repository", |
| 231 | }, |
| 232 | } |
| 233 | |
| 234 | for _, test := range tests { |
| 235 | t.Run(test.name, func(t *testing.T) { |
| 236 | stderr, err := runInit(t, test.args...) |
| 237 | if test.expectError && err == nil { |
| 238 | t.Errorf("%s: expected error, got none\nstderr:\n%s", test.description, stderr) |
| 239 | } |
| 240 | if !test.expectError && err != nil { |
| 241 | t.Errorf("%s: unexpected error: %v\nstderr:\n%s", test.description, err, stderr) |
| 242 | } |
| 243 | }) |
| 244 | } |
| 245 | } |
| 246 | |
| 247 | // Verify trim behavior: leading/trailing spaces in --url should still be |
| 248 | // handled by RunE's strings.TrimSpace before reaching CloneConf. |