| 346 | } |
| 347 | |
| 348 | func TestIsSSHURL(t *testing.T) { |
| 349 | testCases := []struct { |
| 350 | name string |
| 351 | url string |
| 352 | expected bool |
| 353 | }{ |
| 354 | { |
| 355 | name: "SSH URL with ssh:// protocol", |
| 356 | url: "ssh://git@github.com/user/repo.git", |
| 357 | expected: true, |
| 358 | }, |
| 359 | { |
| 360 | name: "SSH URL with git@ format", |
| 361 | url: "git@github.com:user/repo.git", |
| 362 | expected: true, |
| 363 | }, |
| 364 | { |
| 365 | name: "SSH URL with user@host format", |
| 366 | url: "ssh://user@gitlab.com/project/repo.git", |
| 367 | expected: true, |
| 368 | }, |
| 369 | { |
| 370 | name: "HTTPS URL should not be SSH", |
| 371 | url: "https://github.com/user/repo.git", |
| 372 | expected: false, |
| 373 | }, |
| 374 | { |
| 375 | name: "HTTP URL should not be SSH", |
| 376 | url: "http://github.com/user/repo.git", |
| 377 | expected: false, |
| 378 | }, |
| 379 | { |
| 380 | name: "HTTPS URL with port should not be SSH", |
| 381 | url: "https://git@github.com:443/user/repo.git", |
| 382 | expected: false, |
| 383 | }, |
| 384 | { |
| 385 | name: "HTTPS URL with authentication should not be SSH", |
| 386 | url: "https://user@github.com/user/repo.git", |
| 387 | expected: false, |
| 388 | }, |
| 389 | { |
| 390 | name: "File URL should not be SSH", |
| 391 | url: "file:///tmp/repo.git", |
| 392 | expected: false, |
| 393 | }, |
| 394 | } |
| 395 | |
| 396 | for _, testCase := range testCases { |
| 397 | t.Run(testCase.name, func(t *testing.T) { |
| 398 | result := isSSHURL(testCase.url) |
| 399 | if result != testCase.expected { |
| 400 | t.Errorf("Expected %v for %q, got %v", testCase.expected, testCase.url, result) |
| 401 | } |
| 402 | }) |
| 403 | } |
| 404 | } |
| 405 | |