Skip to content

Commit

Permalink
Add AWS S3 support to BBS generate script (#698)
Browse files Browse the repository at this point in the history
  • Loading branch information
ArinGhazarian authored Oct 27, 2022
1 parent ec48413 commit 6d43c5f
Show file tree
Hide file tree
Showing 8 changed files with 604 additions and 42 deletions.
1 change: 1 addition & 0 deletions src/.idea/.idea.OctoshiftCLI/.idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public void Should_Have_Options()
{
_command.Should().NotBeNull();
_command.Name.Should().Be("generate-script");
_command.Options.Count.Should().Be(11);
_command.Options.Count.Should().Be(12);

TestHelpers.VerifyCommandOption(_command.Options, "bbs-server-url", true);
TestHelpers.VerifyCommandOption(_command.Options, "github-org", true);
Expand All @@ -48,6 +48,7 @@ public void Should_Have_Options()
TestHelpers.VerifyCommandOption(_command.Options, "output", false);
TestHelpers.VerifyCommandOption(_command.Options, "kerberos", false, true);
TestHelpers.VerifyCommandOption(_command.Options, "verbose", false);
TestHelpers.VerifyCommandOption(_command.Options, "aws-bucket-name", false);
}

[Fact]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ public class GenerateScriptCommandHandlerTests
private const string BBS_BAR_REPO_2_SLUG = "barrepo2";
private const string BBS_BAR_REPO_2_NAME = "BBS-BAR-REPO-2-NAME";
private const string BBS_SHARED_HOME = "BBS-SHARED-HOME";
private const string AWS_BUCKET_NAME = "AWS-BUCKET-NAME";

public GenerateScriptCommandHandlerTests()
{
Expand All @@ -54,8 +55,8 @@ public GenerateScriptCommandHandlerTests()
_mockBbsApi.Object,
_mockEnvironmentVariableProvider.Object);

_mockEnvironmentVariableProvider.Setup(m => m.BbsUsername()).Returns(BBS_USERNAME);
_mockEnvironmentVariableProvider.Setup(m => m.BbsPassword()).Returns(BBS_PASSWORD);
_mockEnvironmentVariableProvider.Setup(m => m.BbsUsername(It.IsAny<bool>())).Returns(BBS_USERNAME);
_mockEnvironmentVariableProvider.Setup(m => m.BbsPassword(It.IsAny<bool>())).Returns(BBS_PASSWORD);
_mockBbsApi.Setup(m => m.GetProjects()).ReturnsAsync(new[] { (1, BBS_FOO_PROJECT_KEY, BBS_FOO_PROJECT_NAME) });
_mockBbsApi.Setup(m => m.GetRepos(BBS_FOO_PROJECT_KEY)).ReturnsAsync(new[] { (1, BBS_FOO_REPO_1_SLUG, BBS_FOO_REPO_1_NAME) });
}
Expand Down Expand Up @@ -148,8 +149,8 @@ public async Task Two_Projects_Two_Repos_Each_All_Options()
_mockFileSystemProvider.Verify(m => m.WriteAllTextAsync(It.IsAny<string>(), It.Is<string>(script => script.Contains(migrateRepoCommand3))));
_mockFileSystemProvider.Verify(m => m.WriteAllTextAsync(It.IsAny<string>(), It.Is<string>(script => script.Contains(migrateRepoCommand4))));

_mockEnvironmentVariableProvider.Verify(m => m.BbsUsername(), Times.Never);
_mockEnvironmentVariableProvider.Verify(m => m.BbsPassword(), Times.Never);
_mockEnvironmentVariableProvider.Verify(m => m.BbsUsername(It.IsAny<bool>()), Times.Never);
_mockEnvironmentVariableProvider.Verify(m => m.BbsPassword(It.IsAny<bool>()), Times.Never);
}

[Fact]
Expand Down Expand Up @@ -260,6 +261,42 @@ function Exec {
_mockFileSystemProvider.Verify(m => m.WriteAllTextAsync(It.IsAny<string>(), It.Is<string>(script => script.Contains(execFunctionBlock))));
}

[Fact]
public async Task One_Repo_With_Aws_Bucket_Name()
{
// Arrange
_mockBbsApi.Setup(m => m.GetProjects()).ReturnsAsync(new[]
{
(Id: 1, Key: BBS_FOO_PROJECT_KEY, Name: BBS_FOO_PROJECT_NAME),
});
_mockBbsApi.Setup(m => m.GetRepos(BBS_FOO_PROJECT_KEY)).ReturnsAsync(new[]
{
(Id: 1, Slug: BBS_FOO_REPO_1_SLUG, Name: BBS_FOO_REPO_1_NAME),
});

const string migrateRepoCommand = $"Exec {{ gh bbs2gh migrate-repo --bbs-server-url \"{BBS_SERVER_URL}\" --bbs-username \"{BBS_USERNAME}\" --bbs-shared-home \"{BBS_SHARED_HOME}\" --bbs-project \"{BBS_FOO_PROJECT_KEY}\" --bbs-repo \"{BBS_FOO_REPO_1_SLUG}\" --ssh-user \"{SSH_USER}\" --ssh-private-key \"{SSH_PRIVATE_KEY}\" --ssh-port {SSH_PORT} --github-org \"{GITHUB_ORG}\" --github-repo \"{BBS_FOO_PROJECT_KEY}-{BBS_FOO_REPO_1_SLUG}\" --verbose --wait --aws-bucket-name \"{AWS_BUCKET_NAME}\" }}";

// Act
var args = new GenerateScriptCommandArgs
{
BbsServerUrl = BBS_SERVER_URL,
GithubOrg = GITHUB_ORG,
BbsUsername = BBS_USERNAME,
BbsPassword = BBS_PASSWORD,
BbsSharedHome = BBS_SHARED_HOME,
SshUser = SSH_USER,
SshPrivateKey = SSH_PRIVATE_KEY,
SshPort = SSH_PORT,
Output = new FileInfo(OUTPUT),
Verbose = true,
AwsBucketName = AWS_BUCKET_NAME
};
await _handler.Handle(args);

// Assert
_mockFileSystemProvider.Verify(m => m.WriteAllTextAsync(It.IsAny<string>(), It.Is<string>(script => script.Contains(migrateRepoCommand))));
}

private string TrimNonExecutableLines(string script, int skipFirst = 9, int skipLast = 0)
{
var lines = script.Split(new[] { Environment.NewLine, "\n" }, StringSplitOptions.RemoveEmptyEntries).AsEnumerable();
Expand Down
Loading

0 comments on commit 6d43c5f

Please sign in to comment.