4
0

AddRemoteUseCaseTests.cs 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. using RackPeek.Domain.Git;
  2. using RackPeek.Domain.Git.UseCases;
  3. namespace Tests.Git;
  4. public sealed class AddRemoteUseCaseTests : IDisposable {
  5. private readonly string _tempDir;
  6. private readonly IGitRepository _repo;
  7. private readonly AddRemoteUseCase _useCase;
  8. public AddRemoteUseCaseTests() {
  9. _tempDir = Path.Combine(
  10. Path.GetTempPath(),
  11. "rackpeek-add-remote-tests",
  12. Guid.NewGuid().ToString());
  13. Directory.CreateDirectory(_tempDir);
  14. _repo = new LibGit2GitRepository(
  15. _tempDir,
  16. new TokenCredentialsProvider("test", "test-token"));
  17. _useCase = new AddRemoteUseCase(_repo);
  18. }
  19. public void Dispose() {
  20. try {
  21. if (Directory.Exists(_tempDir))
  22. Directory.Delete(_tempDir, true);
  23. }
  24. catch {
  25. // ignore cleanup issues
  26. }
  27. }
  28. [Theory]
  29. [InlineData("https://github.com/youruser/rackpeek-config.git")]
  30. [InlineData("https://gitea.example.com/youruser/rackpeek-config.git")]
  31. [InlineData("https://gitlab.example.com/youruser/rackpeek-config.git")]
  32. public async Task Accepts_Documented_HTTPS_Examples(string url) {
  33. // The doc lists these three URL shapes as supported. Use case must
  34. // not reject them as malformed — a fetch failure (no real remote) is
  35. // acceptable but "Only HTTPS URLs are supported" is not.
  36. var error = await _useCase.ExecuteAsync(url);
  37. Assert.DoesNotContain("Only HTTPS URLs are supported", error ?? string.Empty);
  38. Assert.DoesNotContain("Git is not available", error ?? string.Empty);
  39. }
  40. [Theory]
  41. [InlineData("http://github.com/u/r.git")]
  42. [InlineData("ssh://git@github.com/u/r.git")]
  43. [InlineData("git@github.com:u/r.git")]
  44. [InlineData("file:///tmp/repo")]
  45. public async Task Rejects_Non_HTTPS_URLs(string url) {
  46. // Doc: "RackPeek does not use any host-specific APIs; the integration
  47. // is plain git over HTTPS." Only HTTPS is supported on purpose — SSH
  48. // would need a different credentials flow we don't offer.
  49. var error = await _useCase.ExecuteAsync(url);
  50. Assert.Equal("Only HTTPS URLs are supported.", error);
  51. }
  52. [Fact]
  53. public async Task Rejects_Empty_URL() {
  54. var error = await _useCase.ExecuteAsync(" ");
  55. Assert.Equal("URL is required.", error);
  56. }
  57. [Fact]
  58. public async Task Rejects_When_Remote_Already_Configured() {
  59. await _useCase.ExecuteAsync("https://example.com/first.git");
  60. var error = await _useCase.ExecuteAsync("https://example.com/second.git");
  61. Assert.Equal("Remote already configured.", error);
  62. }
  63. }