|
| 1 | +using FluentAssertions; |
| 2 | +using Moq; |
| 3 | +using OctoshiftCLI.Commands.DownloadLogs; |
| 4 | +using OctoshiftCLI.Services; |
| 5 | +using Xunit; |
| 6 | + |
| 7 | +namespace OctoshiftCLI.Tests.Octoshift.Commands.DownloadLogs; |
| 8 | + |
| 9 | +public class DownloadLogsCommandArgsTests |
| 10 | +{ |
| 11 | + private readonly Mock<OctoLogger> _mockOctoLogger = TestHelpers.CreateMock<OctoLogger>(); |
| 12 | + |
| 13 | + private const string GITHUB_ORG = "foo-org"; |
| 14 | + private const string GITHUB_REPO = "foo-repo"; |
| 15 | + |
| 16 | + [Fact] |
| 17 | + public void Validate_Throws_When_GithubOrg_Is_Url() |
| 18 | + { |
| 19 | + var args = new DownloadLogsCommandArgs |
| 20 | + { |
| 21 | + GithubOrg = "https://github.com/my-org", |
| 22 | + GithubRepo = GITHUB_REPO |
| 23 | + }; |
| 24 | + |
| 25 | + FluentActions.Invoking(() => args.Validate(_mockOctoLogger.Object)) |
| 26 | + .Should() |
| 27 | + .ThrowExactly<OctoshiftCliException>() |
| 28 | + .WithMessage("The --github-org option expects an organization name, not a URL. Please provide just the organization name (e.g., 'my-org' instead of 'https://github.com/my-org')."); |
| 29 | + } |
| 30 | + |
| 31 | + [Fact] |
| 32 | + public void Validate_Throws_When_GithubRepo_Is_Url() |
| 33 | + { |
| 34 | + var args = new DownloadLogsCommandArgs |
| 35 | + { |
| 36 | + GithubOrg = GITHUB_ORG, |
| 37 | + GithubRepo = "http://github.com/org/repo" |
| 38 | + }; |
| 39 | + |
| 40 | + FluentActions.Invoking(() => args.Validate(_mockOctoLogger.Object)) |
| 41 | + .Should() |
| 42 | + .ThrowExactly<OctoshiftCliException>() |
| 43 | + .WithMessage("The --github-repo option expects a repository name, not a URL. Please provide just the repository name (e.g., 'my-repo' instead of 'https://github.com/my-org/my-repo')."); |
| 44 | + } |
| 45 | + |
| 46 | + [Fact] |
| 47 | + public void Validate_Succeeds_With_Valid_Names() |
| 48 | + { |
| 49 | + var args = new DownloadLogsCommandArgs |
| 50 | + { |
| 51 | + GithubOrg = GITHUB_ORG, |
| 52 | + GithubRepo = GITHUB_REPO |
| 53 | + }; |
| 54 | + |
| 55 | + args.Validate(_mockOctoLogger.Object); |
| 56 | + |
| 57 | + args.GithubOrg.Should().Be(GITHUB_ORG); |
| 58 | + args.GithubRepo.Should().Be(GITHUB_REPO); |
| 59 | + } |
| 60 | +} |
0 commit comments