Skip to content

Commit

Permalink
Merge pull request #1318 from github/fix-validate-no-generate-options…
Browse files Browse the repository at this point in the history
…-error-messages

Update no generate validation error messages for bbs2gh migrate-repo
  • Loading branch information
ArinGhazarian authored Dec 19, 2024
2 parents 2b6567d + 4c260fd commit 1b2c02b
Show file tree
Hide file tree
Showing 3 changed files with 98 additions and 12 deletions.
2 changes: 1 addition & 1 deletion RELEASENOTES.md
Original file line number Diff line number Diff line change
@@ -1 +1 @@

- Update validation error messages for `gh bbs2gh migrate-repo` command when generating an archive is not required.
Original file line number Diff line number Diff line change
Expand Up @@ -225,11 +225,12 @@ public void It_Throws_When_Kerberos_Is_Set_And_Bbs_Username_Is_Provided()
}

[Fact]
public void Errors_If_BbsServer_Url_Not_Provided_But_Bbs_Password_Is_Provided()
public void Errors_If_Bbs_Password_Is_Provided_With_Archive_Path()
{
// Act
var args = new MigrateRepoCommandArgs
{
BbsServerUrl = BBS_SERVER_URL,
ArchivePath = ARCHIVE_PATH,
GithubOrg = GITHUB_ORG,
GithubRepo = GITHUB_REPO,
Expand All @@ -240,15 +241,36 @@ public void Errors_If_BbsServer_Url_Not_Provided_But_Bbs_Password_Is_Provided()
args.Invoking(x => x.Validate(_mockOctoLogger.Object))
.Should()
.ThrowExactly<OctoshiftCliException>()
.WithMessage("*--bbs-username*--bbs-password*--bbs-server-url*");
.WithMessage("*--bbs-username*--bbs-password*--archive-path*");
}

[Fact]
public void Errors_If_Bbs_Password_Is_Provided_With_Archive_Url()
{
// Act
var args = new MigrateRepoCommandArgs
{
BbsServerUrl = BBS_SERVER_URL,
ArchiveUrl = ARCHIVE_URL,
GithubOrg = GITHUB_ORG,
GithubRepo = GITHUB_REPO,
BbsPassword = BBS_USERNAME
};

// Assert
args.Invoking(x => x.Validate(_mockOctoLogger.Object))
.Should()
.ThrowExactly<OctoshiftCliException>()
.WithMessage("*--bbs-username*--bbs-password*--archive-url*");
}

[Fact]
public void Errors_If_BbsServer_Url_Not_Provided_But_No_Ssl_Verify_Is_Provided()
public void Errors_If_No_Ssl_Verify_Is_Provided_With_Archive_Path()
{
// Act
var args = new MigrateRepoCommandArgs
{
BbsServerUrl = BBS_SERVER_URL,
ArchivePath = ARCHIVE_PATH,
GithubOrg = GITHUB_ORG,
GithubRepo = GITHUB_REPO,
Expand All @@ -259,15 +281,36 @@ public void Errors_If_BbsServer_Url_Not_Provided_But_No_Ssl_Verify_Is_Provided()
args.Invoking(x => x.Validate(_mockOctoLogger.Object))
.Should()
.ThrowExactly<OctoshiftCliException>()
.WithMessage("*--no-ssl-verify*--bbs-server-url*");
.WithMessage("*--no-ssl-verify*--archive-path*");
}

[Fact]
public void Errors_If_BbsServer_Url_Not_Provided_But_Ssh_User_Is_Provided()
public void Errors_If_No_Ssl_Verify_Is_Provided_With_Archive_Url()
{
// Act
var args = new MigrateRepoCommandArgs
{
BbsServerUrl = BBS_SERVER_URL,
ArchiveUrl = ARCHIVE_URL,
GithubOrg = GITHUB_ORG,
GithubRepo = GITHUB_REPO,
NoSslVerify = true
};

// Assert
args.Invoking(x => x.Validate(_mockOctoLogger.Object))
.Should()
.ThrowExactly<OctoshiftCliException>()
.WithMessage("*--no-ssl-verify*--archive-url*");
}

[Fact]
public void Errors_If_Ssh_User_Is_Provided_With_Archive_Path()
{
// Act
var args = new MigrateRepoCommandArgs
{
BbsServerUrl = BBS_SERVER_URL,
ArchivePath = ARCHIVE_PATH,
GithubOrg = GITHUB_ORG,
GithubRepo = GITHUB_REPO,
Expand All @@ -279,15 +322,37 @@ public void Errors_If_BbsServer_Url_Not_Provided_But_Ssh_User_Is_Provided()
args.Invoking(x => x.Validate(_mockOctoLogger.Object))
.Should()
.ThrowExactly<OctoshiftCliException>()
.WithMessage("*SSH*SMB*--bbs-server-url*");
.WithMessage("*SSH*SMB*--archive-path*");
}

[Fact]
public void Errors_If_BbsServer_Url_Not_Provided_But_Smb_User_Is_Provided()
public void Errors_If_Ssh_User_Is_Provided_With_Archive_Url()
{
// Act
var args = new MigrateRepoCommandArgs
{
BbsServerUrl = BBS_SERVER_URL,
ArchiveUrl = ARCHIVE_URL,
GithubOrg = GITHUB_ORG,
GithubRepo = GITHUB_REPO,
SshUser = SSH_USER,
SshPrivateKey = PRIVATE_KEY,
};

// Assert
args.Invoking(x => x.Validate(_mockOctoLogger.Object))
.Should()
.ThrowExactly<OctoshiftCliException>()
.WithMessage("*SSH*SMB*--archive-url*");
}

[Fact]
public void Errors_If_Smb_User_Is_Provided_With_Archive_Path()
{
// Act
var args = new MigrateRepoCommandArgs
{
BbsServerUrl = BBS_SERVER_URL,
ArchivePath = ARCHIVE_PATH,
GithubOrg = GITHUB_ORG,
GithubRepo = GITHUB_REPO,
Expand All @@ -299,7 +364,28 @@ public void Errors_If_BbsServer_Url_Not_Provided_But_Smb_User_Is_Provided()
args.Invoking(x => x.Validate(_mockOctoLogger.Object))
.Should()
.ThrowExactly<OctoshiftCliException>()
.WithMessage("*SSH*SMB*--bbs-server-url*");
.WithMessage("*SSH*SMB*--archive-path*");
}

[Fact]
public void Errors_If_Smb_User_Is_Provided_With_Archive_Url()
{
// Act
var args = new MigrateRepoCommandArgs
{
BbsServerUrl = BBS_SERVER_URL,
ArchiveUrl = ARCHIVE_URL,
GithubOrg = GITHUB_ORG,
GithubRepo = GITHUB_REPO,
SmbUser = SMB_USER,
SmbPassword = SMB_PASSWORD,
};

// Assert
args.Invoking(x => x.Validate(_mockOctoLogger.Object))
.Should()
.ThrowExactly<OctoshiftCliException>()
.WithMessage("*SSH*SMB*--archive-url*");
}

[Fact]
Expand Down
6 changes: 3 additions & 3 deletions src/bbs2gh/Commands/MigrateRepo/MigrateRepoCommandArgs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -95,17 +95,17 @@ private void ValidateNoGenerateOptions()
{
if (BbsUsername.HasValue() || BbsPassword.HasValue())
{
throw new OctoshiftCliException("--bbs-username and --bbs-password can only be provided with --bbs-server-url.");
throw new OctoshiftCliException("--bbs-username and --bbs-password cannot be provided with --archive-path or --archive-url.");
}

if (NoSslVerify)
{
throw new OctoshiftCliException("--no-ssl-verify can only be provided with --bbs-server-url.");
throw new OctoshiftCliException("--no-ssl-verify cannot be provided with --archive-path or --archive-url.");
}

if (new[] { SshUser, SshPrivateKey, ArchiveDownloadHost, SmbUser, SmbPassword, SmbDomain }.Any(obj => obj.HasValue()))
{
throw new OctoshiftCliException("SSH or SMB download options can only be provided with --bbs-server-url.");
throw new OctoshiftCliException("SSH or SMB download options cannot be provided with --archive-path or --archive-url.");
}
}

Expand Down

0 comments on commit 1b2c02b

Please sign in to comment.