-
Notifications
You must be signed in to change notification settings - Fork 99
/
Copy pathMigrateOrgCommandTests.cs
73 lines (63 loc) · 3.07 KB
/
MigrateOrgCommandTests.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
using FluentAssertions;
using Microsoft.Extensions.DependencyInjection;
using Moq;
using OctoshiftCLI.Contracts;
using OctoshiftCLI.GithubEnterpriseImporter.Commands.MigrateOrg;
using OctoshiftCLI.Services;
using Xunit;
namespace OctoshiftCLI.Tests.GithubEnterpriseImporter.Commands.MigrateOrg
{
public class MigrateOrgCommandTests
{
private readonly Mock<ITargetGithubApiFactory> _mockGithubApiFactory = new();
private readonly Mock<OctoLogger> _mockOctoLogger = TestHelpers.CreateMock<OctoLogger>();
private readonly Mock<EnvironmentVariableProvider> _mockEnvironmentVariableProvider = TestHelpers.CreateMock<EnvironmentVariableProvider>();
private readonly Mock<WarningsCountLogger> _warningsCountLogger = TestHelpers.CreateMock<WarningsCountLogger>();
private readonly ServiceProvider _serviceProvider;
private readonly MigrateOrgCommand _command = new();
public MigrateOrgCommandTests()
{
var serviceCollection = new ServiceCollection();
serviceCollection
.AddSingleton(_mockOctoLogger.Object)
.AddSingleton(_mockGithubApiFactory.Object)
.AddSingleton(_mockEnvironmentVariableProvider.Object)
.AddSingleton(_warningsCountLogger.Object);
_serviceProvider = serviceCollection.BuildServiceProvider();
}
[Fact]
public void Should_Have_Options()
{
var command = new MigrateOrgCommand();
command.Should().NotBeNull();
command.Name.Should().Be("migrate-org");
command.Options.Count.Should().Be(8);
TestHelpers.VerifyCommandOption(command.Options, "github-source-org", true);
TestHelpers.VerifyCommandOption(command.Options, "github-target-org", true);
TestHelpers.VerifyCommandOption(command.Options, "github-target-enterprise", true);
TestHelpers.VerifyCommandOption(command.Options, "queue-only", false);
TestHelpers.VerifyCommandOption(command.Options, "github-source-pat", false);
TestHelpers.VerifyCommandOption(command.Options, "github-target-pat", false);
TestHelpers.VerifyCommandOption(command.Options, "verbose", false);
TestHelpers.VerifyCommandOption(command.Options, "target-api-url", false);
}
[Fact]
public void It_Uses_Target_Api_Url_When_Provided()
{
var githubSourcePat = "abc123";
var githubTargetPat = "def456";
var targetApiUrl = "https://api.github.com";
var args = new MigrateOrgCommandArgs
{
GithubSourceOrg = "source-org",
GithubSourcePat = githubSourcePat,
GithubTargetOrg = "target-org",
GithubTargetEnterprise = "target-enterprise",
GithubTargetPat = githubTargetPat,
TargetApiUrl = targetApiUrl
};
_command.BuildHandler(args, _serviceProvider);
_mockGithubApiFactory.Verify(m => m.Create(targetApiUrl, githubTargetPat));
}
}
}