Skip to content

Commit

Permalink
Merge pull request #1295 from github/arin-fix-bug
Browse files Browse the repository at this point in the history
Remove useGithubStorage from GHES version checker method
  • Loading branch information
begonaguereca authored Nov 15, 2024
2 parents 8ad4cf8 + edf8870 commit 0917c73
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 45 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@
using Moq;
using OctoshiftCLI.Extensions;
using OctoshiftCLI.Services;
using OctoshiftCLI.Tests;
using Xunit;

namespace OctoshiftCLI.Tests.Octoshift.Services;

public class ArchiveUploaderTests
{
private readonly Mock<GithubClient> _githubClientMock;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ public async Task Sequential_Github_Ghes_Repo()
_mockGithubApi
.Setup(m => m.GetRepos(SOURCE_ORG))
.ReturnsAsync(new[] { (REPO, "private") });
_mockGhesVersionCheckerService.Setup(m => m.AreBlobCredentialsRequired(ghesApiUrl, false)).ReturnsAsync(true);
_mockGhesVersionCheckerService.Setup(m => m.AreBlobCredentialsRequired(ghesApiUrl)).ReturnsAsync(true);

var expected = $"Exec {{ gh gei migrate-repo --github-source-org \"{SOURCE_ORG}\" --source-repo \"{REPO}\" --github-target-org \"{TARGET_ORG}\" --target-repo \"{REPO}\" --ghes-api-url \"{ghesApiUrl}\" --target-repo-visibility private }}";

Expand Down Expand Up @@ -333,7 +333,7 @@ public async Task Parallel_Github_Ghes_Single_Repo()
.ReturnsAsync(new[] { (REPO, "private") });

_mockVersionProvider.Setup(m => m.GetCurrentVersion()).Returns("1.1.1");
_mockGhesVersionCheckerService.Setup(m => m.AreBlobCredentialsRequired(ghesApiUrl, false)).ReturnsAsync(true);
_mockGhesVersionCheckerService.Setup(m => m.AreBlobCredentialsRequired(ghesApiUrl)).ReturnsAsync(true);

var expected = new StringBuilder();
expected.AppendLine("#!/usr/bin/env pwsh");
Expand Down Expand Up @@ -502,7 +502,7 @@ public async Task Parallel_Github_Ghes_Single_Repo_With_Download_Migration_Logs(
.ReturnsAsync(new[] { (REPO, "private") });

_mockVersionProvider.Setup(m => m.GetCurrentVersion()).Returns("1.1.1");
_mockGhesVersionCheckerService.Setup(m => m.AreBlobCredentialsRequired(ghesApiUrl, false)).ReturnsAsync(true);
_mockGhesVersionCheckerService.Setup(m => m.AreBlobCredentialsRequired(ghesApiUrl)).ReturnsAsync(true);

var expected = new StringBuilder();
expected.AppendLine("#!/usr/bin/env pwsh");
Expand Down Expand Up @@ -588,7 +588,7 @@ public async Task Parallel_Github_Ghes_Single_Repo_No_Ssl()
.ReturnsAsync(new[] { (REPO, "private") });

_mockVersionProvider.Setup(m => m.GetCurrentVersion()).Returns("1.1.1");
_mockGhesVersionCheckerService.Setup(m => m.AreBlobCredentialsRequired(ghesApiUrl, false)).ReturnsAsync(true);
_mockGhesVersionCheckerService.Setup(m => m.AreBlobCredentialsRequired(ghesApiUrl)).ReturnsAsync(true);

var expected = new StringBuilder();
expected.AppendLine("#!/usr/bin/env pwsh");
Expand Down Expand Up @@ -673,7 +673,7 @@ public async Task Parallel_Github_Ghes_Single_Repo_Keep_Archive()
.ReturnsAsync(new[] { (REPO, "private") });

_mockVersionProvider.Setup(m => m.GetCurrentVersion()).Returns("1.1.1");
_mockGhesVersionCheckerService.Setup(m => m.AreBlobCredentialsRequired(ghesApiUrl, false)).ReturnsAsync(false);
_mockGhesVersionCheckerService.Setup(m => m.AreBlobCredentialsRequired(ghesApiUrl)).ReturnsAsync(false);

var expected = new StringBuilder();
expected.AppendLine("#!/usr/bin/env pwsh");
Expand Down Expand Up @@ -909,7 +909,7 @@ public async Task Sequential_Ghes_Single_Repo_Aws_S3()
_mockGithubApi
.Setup(m => m.GetRepos(SOURCE_ORG))
.ReturnsAsync(new[] { (REPO, "private") });
_mockGhesVersionCheckerService.Setup(m => m.AreBlobCredentialsRequired(ghesApiUrl, false)).ReturnsAsync(true);
_mockGhesVersionCheckerService.Setup(m => m.AreBlobCredentialsRequired(ghesApiUrl)).ReturnsAsync(true);

var expected = $"Exec {{ gh gei migrate-repo --github-source-org \"{SOURCE_ORG}\" --source-repo \"{REPO}\" --github-target-org \"{TARGET_ORG}\" --target-repo \"{REPO}\" --ghes-api-url \"{ghesApiUrl}\" --aws-bucket-name \"{AWS_BUCKET_NAME}\" --aws-region \"{AWS_REGION}\" --target-repo-visibility private }}";

Expand Down Expand Up @@ -941,7 +941,7 @@ public async Task Sequential_Ghes_Single_Repo_Keep_Archive()
_mockGithubApi
.Setup(m => m.GetRepos(SOURCE_ORG))
.ReturnsAsync(new[] { (REPO, "private") });
_mockGhesVersionCheckerService.Setup(m => m.AreBlobCredentialsRequired(ghesApiUrl, false)).ReturnsAsync(true);
_mockGhesVersionCheckerService.Setup(m => m.AreBlobCredentialsRequired(ghesApiUrl)).ReturnsAsync(true);

var expected = $"Exec {{ gh gei migrate-repo --github-source-org \"{SOURCE_ORG}\" --source-repo \"{REPO}\" --github-target-org \"{TARGET_ORG}\" --target-repo \"{REPO}\" --ghes-api-url \"{ghesApiUrl}\" --aws-bucket-name \"{AWS_BUCKET_NAME}\" --aws-region \"{AWS_REGION}\" --keep-archive --target-repo-visibility private }}";

Expand Down Expand Up @@ -974,7 +974,7 @@ public async Task Validates_Env_Vars()
_mockGithubApi
.Setup(m => m.GetRepos(SOURCE_ORG))
.ReturnsAsync(new[] { (REPO, "private") });
_mockGhesVersionCheckerService.Setup(m => m.AreBlobCredentialsRequired(ghesApiUrl, false)).ReturnsAsync(true);
_mockGhesVersionCheckerService.Setup(m => m.AreBlobCredentialsRequired(ghesApiUrl)).ReturnsAsync(true);

var expected = @"
if (-not $env:GH_PAT) {
Expand Down Expand Up @@ -1019,7 +1019,7 @@ public async Task Validates_Env_Vars_AWS()
_mockGithubApi
.Setup(m => m.GetRepos(SOURCE_ORG))
.ReturnsAsync(new[] { (REPO, "private") });
_mockGhesVersionCheckerService.Setup(m => m.AreBlobCredentialsRequired(ghesApiUrl, false)).ReturnsAsync(true);
_mockGhesVersionCheckerService.Setup(m => m.AreBlobCredentialsRequired(ghesApiUrl)).ReturnsAsync(true);

var expected = @"
if (-not $env:GH_PAT) {
Expand Down Expand Up @@ -1072,7 +1072,7 @@ public async Task Validates_Env_Vars_AZURE_STORAGE_CONNECTION_STRING_Not_Validat
_mockGithubApi
.Setup(m => m.GetRepos(SOURCE_ORG))
.ReturnsAsync(new[] { (REPO, "private") });
_mockGhesVersionCheckerService.Setup(m => m.AreBlobCredentialsRequired(ghesApiUrl, false)).ReturnsAsync(true);
_mockGhesVersionCheckerService.Setup(m => m.AreBlobCredentialsRequired(ghesApiUrl)).ReturnsAsync(true);

var expected = @"
if (-not $env:AZURE_STORAGE_CONNECTION_STRING) {
Expand Down Expand Up @@ -1173,7 +1173,7 @@ public async Task Validates_Env_Vars_Blob_Storage_Not_Validated_When_GHES_3_8()
_mockGithubApi
.Setup(m => m.GetRepos(SOURCE_ORG))
.ReturnsAsync(new[] { (REPO, "private") });
_mockGhesVersionCheckerService.Setup(m => m.AreBlobCredentialsRequired(ghesApiUrl, false)).ReturnsAsync(false);
_mockGhesVersionCheckerService.Setup(m => m.AreBlobCredentialsRequired(ghesApiUrl)).ReturnsAsync(false);

var expected = @"
if (-not $env:GH_PAT) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public async Task Dont_Generate_Archives_If_Target_Repo_Exists()
{
// Arrange
_mockTargetGithubApi.Setup(x => x.DoesRepoExist(TARGET_ORG, TARGET_REPO)).ReturnsAsync(true);
_mockGhesVersionChecker.Setup(m => m.AreBlobCredentialsRequired(GHES_API_URL, false)).ReturnsAsync(true);
_mockGhesVersionChecker.Setup(m => m.AreBlobCredentialsRequired(GHES_API_URL)).ReturnsAsync(true);

// Act
var args = new MigrateRepoCommandArgs
Expand Down Expand Up @@ -306,7 +306,7 @@ public async Task Happy_Path_GithubSource_Ghes()
_mockEnvironmentVariableProvider.Setup(m => m.SourceGithubPersonalAccessToken(It.IsAny<bool>())).Returns(sourceGithubPat);
_mockEnvironmentVariableProvider.Setup(m => m.TargetGithubPersonalAccessToken(It.IsAny<bool>())).Returns(targetGithubPat);

_mockGhesVersionChecker.Setup(m => m.AreBlobCredentialsRequired(GHES_API_URL, false)).ReturnsAsync(true);
_mockGhesVersionChecker.Setup(m => m.AreBlobCredentialsRequired(GHES_API_URL)).ReturnsAsync(true);

var args = new MigrateRepoCommandArgs
{
Expand All @@ -325,8 +325,10 @@ public async Task Happy_Path_GithubSource_Ghes()
_mockFileSystemProvider.Verify(x => x.DeleteIfExists(metadataArchiveFilePath), Times.Once);
}

[Fact]
public async Task Happy_Path_UseGithubStorage()
[Theory]
[InlineData(false)]
[InlineData(true)]
public async Task Happy_Path_UseGithubStorage(bool useGhesBlobCredentials)
{
var githubOrgId = Guid.NewGuid().ToString();
var githubOrgDatabaseId = Guid.NewGuid().ToString();
Expand Down Expand Up @@ -365,7 +367,7 @@ public async Task Happy_Path_UseGithubStorage()
.Setup(m => m.OpenRead(metadataArchiveDownloadFilePath))
.Returns(metaContentStream);

_mockGhesVersionChecker.Setup(m => m.AreBlobCredentialsRequired(GHES_API_URL, true)).ReturnsAsync(true);
_mockGhesVersionChecker.Setup(m => m.AreBlobCredentialsRequired(GHES_API_URL)).ReturnsAsync(useGhesBlobCredentials);

_mockTargetGithubApi.Setup(x => x.DoesOrgExist(TARGET_ORG).Result).Returns(true);

Expand Down Expand Up @@ -482,7 +484,7 @@ public async Task Happy_Path_GithubSource_Ghes_Repo_Renamed()
_mockEnvironmentVariableProvider.Setup(m => m.SourceGithubPersonalAccessToken(It.IsAny<bool>())).Returns(sourceGithubPat);
_mockEnvironmentVariableProvider.Setup(m => m.TargetGithubPersonalAccessToken(It.IsAny<bool>())).Returns(targetGithubPat);

_mockGhesVersionChecker.Setup(m => m.AreBlobCredentialsRequired(GHES_API_URL, false)).ReturnsAsync(true);
_mockGhesVersionChecker.Setup(m => m.AreBlobCredentialsRequired(GHES_API_URL)).ReturnsAsync(true);

var args = new MigrateRepoCommandArgs
{
Expand Down Expand Up @@ -635,7 +637,7 @@ public async Task Ghes_AzureConnectionString_Uses_Env_When_Option_Empty()
_mockEnvironmentVariableProvider.Setup(m => m.TargetGithubPersonalAccessToken(It.IsAny<bool>())).Returns(targetGithubPat);
_mockEnvironmentVariableProvider.Setup(m => m.AzureStorageConnectionString(It.IsAny<bool>())).Returns(azureConnectionStringEnv);

_mockGhesVersionChecker.Setup(m => m.AreBlobCredentialsRequired(GHES_API_URL, false)).ReturnsAsync(true);
_mockGhesVersionChecker.Setup(m => m.AreBlobCredentialsRequired(GHES_API_URL)).ReturnsAsync(true);

var args = new MigrateRepoCommandArgs
{
Expand Down Expand Up @@ -699,7 +701,7 @@ public async Task Ghes_With_NoSslVerify_Uses_NoSsl_Client()
_mockEnvironmentVariableProvider.Setup(m => m.SourceGithubPersonalAccessToken(It.IsAny<bool>())).Returns(sourceGithubPat);
_mockEnvironmentVariableProvider.Setup(m => m.TargetGithubPersonalAccessToken(It.IsAny<bool>())).Returns(targetGithubPat);

_mockGhesVersionChecker.Setup(m => m.AreBlobCredentialsRequired(GHES_API_URL, false)).ReturnsAsync(true);
_mockGhesVersionChecker.Setup(m => m.AreBlobCredentialsRequired(GHES_API_URL)).ReturnsAsync(true);

var args = new MigrateRepoCommandArgs
{
Expand Down Expand Up @@ -762,7 +764,7 @@ public async Task Ghes_With_3_8_0_Version_Returns_Archive_Urls_Directly()
_mockEnvironmentVariableProvider.Setup(m => m.SourceGithubPersonalAccessToken(It.IsAny<bool>())).Returns(sourceGithubPat);
_mockEnvironmentVariableProvider.Setup(m => m.TargetGithubPersonalAccessToken(It.IsAny<bool>())).Returns(targetGithubPat);

_mockGhesVersionChecker.Setup(m => m.AreBlobCredentialsRequired(GHES_API_URL, false)).ReturnsAsync(false);
_mockGhesVersionChecker.Setup(m => m.AreBlobCredentialsRequired(GHES_API_URL)).ReturnsAsync(false);

var args = new MigrateRepoCommandArgs
{
Expand All @@ -789,7 +791,7 @@ public async Task Ghes_Failed_Archive_Generation_Throws_Error()
_mockSourceGithubApi.Setup(x => x.StartMetadataArchiveGeneration(SOURCE_ORG, SOURCE_REPO, false, false).Result).Returns(metadataArchiveId);
_mockSourceGithubApi.Setup(x => x.GetArchiveMigrationStatus(SOURCE_ORG, gitArchiveId).Result).Returns(ArchiveMigrationStatus.Failed);

_mockGhesVersionChecker.Setup(m => m.AreBlobCredentialsRequired(GHES_API_URL, false)).ReturnsAsync(true);
_mockGhesVersionChecker.Setup(m => m.AreBlobCredentialsRequired(GHES_API_URL)).ReturnsAsync(true);

await FluentActions
.Invoking(async () => await _handler.Handle(new MigrateRepoCommandArgs
Expand Down Expand Up @@ -881,7 +883,7 @@ public async Task Ghes_Retries_Archive_Generation_On_Any_Error()
_mockEnvironmentVariableProvider.Setup(m => m.SourceGithubPersonalAccessToken(It.IsAny<bool>())).Returns(sourceGithubPat);
_mockEnvironmentVariableProvider.Setup(m => m.TargetGithubPersonalAccessToken(It.IsAny<bool>())).Returns(targetGithubPat);

_mockGhesVersionChecker.Setup(m => m.AreBlobCredentialsRequired(GHES_API_URL, false)).ReturnsAsync(true);
_mockGhesVersionChecker.Setup(m => m.AreBlobCredentialsRequired(GHES_API_URL)).ReturnsAsync(true);

var args = new MigrateRepoCommandArgs
{
Expand Down Expand Up @@ -1065,7 +1067,7 @@ public async Task Does_Not_Pass_Lock_Repos_To_StartMigration_For_GHES()
_mockTargetGithubApi.Setup(x => x.DoesOrgExist(TARGET_ORG).Result).Returns(true);

_mockAzureApi.Setup(x => x.UploadToBlob(It.IsAny<string>(), It.IsAny<Stream>()).Result).Returns(new Uri("https://example.com/resource"));
_mockGhesVersionChecker.Setup(m => m.AreBlobCredentialsRequired(GHES_API_URL, false)).ReturnsAsync(true);
_mockGhesVersionChecker.Setup(m => m.AreBlobCredentialsRequired(GHES_API_URL)).ReturnsAsync(true);

// Act
var args = new MigrateRepoCommandArgs
Expand Down Expand Up @@ -1329,7 +1331,7 @@ public async Task It_Uses_Aws_If_Arguments_Are_Included()

_mockAwsApi.Setup(m => m.UploadToBucket(awsBucketName, It.IsAny<Stream>(), It.IsAny<string>())).ReturnsAsync(archiveUrl);

_mockGhesVersionChecker.Setup(m => m.AreBlobCredentialsRequired(GHES_API_URL, false)).ReturnsAsync(true);
_mockGhesVersionChecker.Setup(m => m.AreBlobCredentialsRequired(GHES_API_URL)).ReturnsAsync(true);

var handler = new MigrateRepoCommandHandler(
_mockOctoLogger.Object,
Expand Down Expand Up @@ -1368,7 +1370,7 @@ public async Task It_Uses_Aws_If_Arguments_Are_Included()
[Fact]
public async Task Ghes_With_Both_Azure_Storage_Connection_String_And_Aws_Bucket_Name_Throws()
{
_mockGhesVersionChecker.Setup(m => m.AreBlobCredentialsRequired(GHES_API_URL, false)).ReturnsAsync(true);
_mockGhesVersionChecker.Setup(m => m.AreBlobCredentialsRequired(GHES_API_URL)).ReturnsAsync(true);

await _handler.Invoking(async x => await x.Handle(new MigrateRepoCommandArgs
{
Expand All @@ -1387,7 +1389,7 @@ await _handler.Invoking(async x => await x.Handle(new MigrateRepoCommandArgs
[Fact]
public async Task Ghes_When_Aws_Bucket_Name_Is_Provided_But_No_Aws_Access_Key_Id_Throws()
{
_mockGhesVersionChecker.Setup(m => m.AreBlobCredentialsRequired(GHES_API_URL, false)).ReturnsAsync(true);
_mockGhesVersionChecker.Setup(m => m.AreBlobCredentialsRequired(GHES_API_URL)).ReturnsAsync(true);

await _handler.Invoking(async x => await x.Handle(new MigrateRepoCommandArgs
{
Expand All @@ -1407,7 +1409,7 @@ await _handler.Invoking(async x => await x.Handle(new MigrateRepoCommandArgs
[Fact]
public async Task Ghes_When_Aws_Bucket_Name_Is_Provided_But_No_Aws_Secret_Key_Throws()
{
_mockGhesVersionChecker.Setup(m => m.AreBlobCredentialsRequired(GHES_API_URL, false)).ReturnsAsync(true);
_mockGhesVersionChecker.Setup(m => m.AreBlobCredentialsRequired(GHES_API_URL)).ReturnsAsync(true);

await _handler.Invoking(async x => await x.Handle(new MigrateRepoCommandArgs
{
Expand All @@ -1427,7 +1429,7 @@ await _handler.Invoking(async x => await x.Handle(new MigrateRepoCommandArgs
[Fact]
public async Task Ghes_When_Aws_Bucket_Name_Is_Provided_But_No_Aws_Region_Throws()
{
_mockGhesVersionChecker.Setup(m => m.AreBlobCredentialsRequired(GHES_API_URL, false)).ReturnsAsync(true);
_mockGhesVersionChecker.Setup(m => m.AreBlobCredentialsRequired(GHES_API_URL)).ReturnsAsync(true);

await _handler.Invoking(async x => await x.Handle(new MigrateRepoCommandArgs
{
Expand All @@ -1449,7 +1451,7 @@ await _handler.Invoking(async x => await x.Handle(new MigrateRepoCommandArgs
[Fact]
public async Task Ghes_When_Aws_Bucket_Name_Not_Provided_But_Aws_Access_Key_Provided()
{
_mockGhesVersionChecker.Setup(m => m.AreBlobCredentialsRequired(GHES_API_URL, false)).ReturnsAsync(true);
_mockGhesVersionChecker.Setup(m => m.AreBlobCredentialsRequired(GHES_API_URL)).ReturnsAsync(true);

await _handler.Invoking(async x => await x.Handle(new MigrateRepoCommandArgs
{
Expand All @@ -1469,7 +1471,7 @@ await _handler.Invoking(async x => await x.Handle(new MigrateRepoCommandArgs
[Fact]
public async Task Ghes_When_Aws_Bucket_Name_Not_Provided_But_Aws_Secret_Key_Provided()
{
_mockGhesVersionChecker.Setup(m => m.AreBlobCredentialsRequired(GHES_API_URL, false)).ReturnsAsync(true);
_mockGhesVersionChecker.Setup(m => m.AreBlobCredentialsRequired(GHES_API_URL)).ReturnsAsync(true);

await _handler.Invoking(async x => await x.Handle(new MigrateRepoCommandArgs
{
Expand All @@ -1489,7 +1491,7 @@ await _handler.Invoking(async x => await x.Handle(new MigrateRepoCommandArgs
[Fact]
public async Task Ghes_When_Aws_Bucket_Name_Not_Provided_But_Aws_Session_Token_Provided()
{
_mockGhesVersionChecker.Setup(m => m.AreBlobCredentialsRequired(GHES_API_URL, false)).ReturnsAsync(true);
_mockGhesVersionChecker.Setup(m => m.AreBlobCredentialsRequired(GHES_API_URL)).ReturnsAsync(true);

await _handler.Invoking(async x => await x.Handle(new MigrateRepoCommandArgs
{
Expand All @@ -1509,7 +1511,7 @@ await _handler.Invoking(async x => await x.Handle(new MigrateRepoCommandArgs
[Fact]
public async Task Ghes_When_Aws_Bucket_Name_Not_Provided_But_Aws_Region_Provided()
{
_mockGhesVersionChecker.Setup(m => m.AreBlobCredentialsRequired(GHES_API_URL, false)).ReturnsAsync(true);
_mockGhesVersionChecker.Setup(m => m.AreBlobCredentialsRequired(GHES_API_URL)).ReturnsAsync(true);

await _handler.Invoking(async x => await x.Handle(new MigrateRepoCommandArgs
{
Expand Down Expand Up @@ -1581,7 +1583,7 @@ public async Task Keep_Archive_Does_Not_Call_DeleteIfExists()
_mockEnvironmentVariableProvider.Setup(m => m.SourceGithubPersonalAccessToken(It.IsAny<bool>())).Returns(sourceGithubPat);
_mockEnvironmentVariableProvider.Setup(m => m.TargetGithubPersonalAccessToken(It.IsAny<bool>())).Returns(targetGithubPat);

_mockGhesVersionChecker.Setup(m => m.AreBlobCredentialsRequired(GHES_API_URL, false)).ReturnsAsync(true);
_mockGhesVersionChecker.Setup(m => m.AreBlobCredentialsRequired(GHES_API_URL)).ReturnsAsync(true);

var args = new MigrateRepoCommandArgs
{
Expand Down
Loading

0 comments on commit 0917c73

Please sign in to comment.