Skip to content

Commit

Permalink
add support for abort migration and rename files as needed
Browse files Browse the repository at this point in the history
  • Loading branch information
brianaj committed Feb 6, 2024
1 parent 49dd24d commit 0f8e926
Show file tree
Hide file tree
Showing 7 changed files with 58 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ public class AbortMigrationCommandArgs : CommandArgs
public string MigrationId { get; set; }
[Secret]
public string GithubPat { get; set; }
public string TargetApiUrl { get; set; }

public override void Validate(OctoLogger log)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,16 @@ public AbortMigrationCommandBase() : base(
{
Description = "Display more information to the console."
};

public Option<string> TargetApiUrl { get; } = new("--target-api-url")
{
Description = "The URL of the target API, if not migrating to github.com. Defaults to https://api.github.com"
};
protected void AddOptions()
{
AddOption(MigrationId);
AddOption(GithubPat);
AddOption(Verbose);
AddOption(TargetApiUrl);
}

public override AbortMigrationCommandHandler BuildHandler(AbortMigrationCommandArgs args, IServiceProvider sp)
Expand All @@ -51,7 +55,7 @@ public override AbortMigrationCommandHandler BuildHandler(AbortMigrationCommandA
}

var log = sp.GetRequiredService<OctoLogger>();
var githubApi = sp.GetRequiredService<ITargetGithubApiFactory>().Create(targetPersonalAccessToken: args.GithubPat);
var githubApi = sp.GetRequiredService<ITargetGithubApiFactory>().Create(args.TargetApiUrl, args.GithubPat);

return new AbortMigrationCommandHandler(log, githubApi);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
using Microsoft.Extensions.DependencyInjection;
using Moq;
using OctoshiftCLI.Commands.AbortMigration;
using OctoshiftCLI.Contracts;
using OctoshiftCLI.Services;
using Xunit;

namespace OctoshiftCLI.Tests.Octoshift.Commands.AbortMigration;

public class AbortMigrationCommandBaseTests
{
private readonly Mock<ITargetGithubApiFactory> _mockGithubApiFactory = new();
private readonly Mock<OctoLogger> _mockOctoLogger = TestHelpers.CreateMock<OctoLogger>();
private readonly ServiceProvider _serviceProvider;
private readonly AbortMigrationCommandBase _command = new();

private const string REPO_MIGRATION_ID = "RM_MIGRATION_ID";

public AbortMigrationCommandBaseTests()
{
var serviceCollection = new ServiceCollection();
serviceCollection
.AddSingleton(_mockOctoLogger.Object)
.AddSingleton(_mockGithubApiFactory.Object);

_serviceProvider = serviceCollection.BuildServiceProvider();
}

[Fact]
public void It_Uses_The_TargetApiUrl_When_Provided()
{
var targetApiUrl = "TargetApiUrl";

var args = new AbortMigrationCommandArgs
{
MigrationId = REPO_MIGRATION_ID,
TargetApiUrl = targetApiUrl
};

_command.BuildHandler(args, _serviceProvider);

_mockGithubApiFactory.Verify(m => m.Create(targetApiUrl, It.IsAny<string>()));
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,11 @@ public void Should_Have_Options()
var command = new AbortMigrationCommand();
command.Should().NotBeNull();
command.Name.Should().Be("abort-migration");
command.Options.Count.Should().Be(3);
command.Options.Count.Should().Be(4);

TestHelpers.VerifyCommandOption(command.Options, "migration-id", true);
TestHelpers.VerifyCommandOption(command.Options, "github-pat", false);
TestHelpers.VerifyCommandOption(command.Options, "verbose", false);
TestHelpers.VerifyCommandOption(command.Options, "target-api-url", false);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,11 @@ public void Should_Have_Options()
var command = new AbortMigrationCommand();
command.Should().NotBeNull();
command.Name.Should().Be("abort-migration");
command.Options.Count.Should().Be(3);
command.Options.Count.Should().Be(4);

TestHelpers.VerifyCommandOption(command.Options, "migration-id", true);
TestHelpers.VerifyCommandOption(command.Options, "github-pat", false);
TestHelpers.VerifyCommandOption(command.Options, "verbose", false);
TestHelpers.VerifyCommandOption(command.Options, "target-api-url", false);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,11 @@ public void Should_Have_Options()
var command = new AbortMigrationCommand();
command.Should().NotBeNull();
command.Name.Should().Be("abort-migration");
command.Options.Count.Should().Be(3);
command.Options.Count.Should().Be(4);

TestHelpers.VerifyCommandOption(command.Options, "migration-id", true);
TestHelpers.VerifyCommandOption(command.Options, "github-pat", false);
TestHelpers.VerifyCommandOption(command.Options, "verbose", false);
TestHelpers.VerifyCommandOption(command.Options, "target-api-url", false);
}
}

0 comments on commit 0f8e926

Please sign in to comment.