-
Notifications
You must be signed in to change notification settings - Fork 117
Fixed the Validation for bbs-shared-home and archive-path #1327
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 5 commits
4e6a04b
ad1004a
110c30a
be2b9da
d302f8b
58bf290
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -455,7 +455,7 @@ public async Task AddRepoToBoardsGithubConnection_Should_Send_Correct_Payload() | |
} | ||
}; | ||
|
||
await sut.AddRepoToBoardsGithubConnection(ADO_ORG, ADO_TEAM_PROJECT, connectionId, connectionName, endpointId, new List<string>() { ADO_REPO, repo2 }); | ||
await sut.AddRepoToBoardsGithubConnection(ADO_ORG, ADO_TEAM_PROJECT, connectionId, connectionName, endpointId, [ADO_REPO, repo2]); | ||
|
||
_mockAdoClient.Verify(m => m.PostAsync(endpoint, It.Is<object>(y => y.ToJson() == payload.ToJson())).Result); | ||
} | ||
|
@@ -551,7 +551,7 @@ public async Task GetLastPushDate_Should_Return_LastPushDate() | |
{ | ||
value = new[] | ||
{ | ||
new { date = expectedDate.ToShortDateString() } | ||
new { date = expectedDate.ToString("o") } | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This caused an error OctoshiftCLI.Tests.Octoshift.Services.AdoApiTests.GetLastPushDate_Should_Return_LastPushDate [9 ms] Solution is the JSON response must provide a date in a standardized format like "yyyy-MM-ddTHH:mm:ssZ". Then only the test case is passed. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the test passes on CI so there must be some issue on your local env. |
||
} | ||
}; | ||
|
||
|
Original file line number | Diff line number | Diff line change | ||
---|---|---|---|---|
|
@@ -251,12 +251,15 @@ | |||
const string bbsSharedHome = "bbs-shared-home"; | ||||
var archivePath = $"{bbsSharedHome}/data/migration/export/Bitbucket_export_{BBS_EXPORT_ID}.tar"; | ||||
|
||||
_mockGithubApi.Setup(x => x.DoesRepoExist(GITHUB_ORG, GITHUB_REPO).Result).Returns(false); | ||||
// Mock directory existence check | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: please avoid adding unnecessary comments as they add unnecessary noise\
Suggested change
|
||||
_mockFileSystemProvider.Setup(m => m.DirectoryExists(bbsSharedHome)).Returns(true); | ||||
|
||||
_mockGithubApi.Setup(x => x.DoesRepoExist(GITHUB_ORG, GITHUB_REPO)).ReturnsAsync(false); | ||||
_mockBbsApi.Setup(x => x.StartExport(BBS_PROJECT, BBS_REPO)).ReturnsAsync(BBS_EXPORT_ID); | ||||
_mockBbsApi.Setup(x => x.GetExport(BBS_EXPORT_ID)).ReturnsAsync(("COMPLETED", "The export is complete", 100)); | ||||
_mockAzureApi.Setup(x => x.UploadToBlob(It.IsAny<string>(), It.IsAny<FileStream>())).ReturnsAsync(new Uri(ARCHIVE_URL)); | ||||
_mockGithubApi.Setup(x => x.GetOrganizationId(GITHUB_ORG).Result).Returns(GITHUB_ORG_ID); | ||||
_mockGithubApi.Setup(x => x.CreateBbsMigrationSource(GITHUB_ORG_ID).Result).Returns(MIGRATION_SOURCE_ID); | ||||
_mockGithubApi.Setup(x => x.GetOrganizationId(GITHUB_ORG)).ReturnsAsync(GITHUB_ORG_ID); | ||||
_mockGithubApi.Setup(x => x.CreateBbsMigrationSource(GITHUB_ORG_ID)).ReturnsAsync(MIGRATION_SOURCE_ID); | ||||
Comment on lines
+261
to
+262
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This change is not necessary, as described here There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Error Message: Solution I used: There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this comment was about reverting the refactor which wasn't necessary. |
||||
|
||||
// Act | ||||
var args = new MigrateRepoCommandArgs | ||||
|
@@ -279,7 +282,7 @@ | |||
_mockGithubApi.Object, | ||||
_mockBbsApi.Object, | ||||
_mockEnvironmentVariableProvider.Object, | ||||
null, // in case of running on Bitbucket server, the downloader will be null | ||||
null, // In case of running on Bitbucket server, the downloader will be null | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same |
||||
_mockAzureApi.Object, | ||||
_mockAwsApi.Object, | ||||
_mockFileSystemProvider.Object, | ||||
|
@@ -355,17 +358,19 @@ | |||
|
||||
await using var gitContentStream = new MemoryStream(gitArchiveContents.ToBytes()); | ||||
|
||||
// Mock file system to return a valid file | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same here
Suggested change
|
||||
_mockFileSystemProvider.Setup(m => m.FileExists(gitArchiveFilePath)).Returns(true); | ||||
_mockFileSystemProvider.Setup(m => m.OpenRead(gitArchiveFilePath)).Returns(gitContentStream); | ||||
|
||||
_mockGithubApi.Setup(x => x.GetOrganizationId(GITHUB_ORG).Result).Returns(GITHUB_ORG_ID); | ||||
_mockGithubApi.Setup(x => x.CreateBbsMigrationSource(GITHUB_ORG_ID).Result).Returns(MIGRATION_SOURCE_ID); | ||||
_mockGithubApi.Setup(x => x.GetOrganizationDatabaseId(GITHUB_ORG).Result).Returns(githubOrgDatabaseId); | ||||
_mockGithubApi.Setup(x => x.GetOrganizationId(GITHUB_ORG)).ReturnsAsync(GITHUB_ORG_ID); | ||||
_mockGithubApi.Setup(x => x.CreateBbsMigrationSource(GITHUB_ORG_ID)).ReturnsAsync(MIGRATION_SOURCE_ID); | ||||
_mockGithubApi.Setup(x => x.GetOrganizationDatabaseId(GITHUB_ORG)).ReturnsAsync(githubOrgDatabaseId); | ||||
_mockGithubApi | ||||
.Setup(x => x.UploadArchiveToGithubStorage( | ||||
githubOrgDatabaseId, | ||||
It.IsAny<string>(), | ||||
It.Is<Stream>(s => (s as MemoryStream).ToArray().GetString() == gitArchiveContents)).Result) | ||||
.Returns(gitArchiveUrl); | ||||
It.Is<Stream>(s => (s as MemoryStream).ToArray().GetString() == gitArchiveContents))) | ||||
.ReturnsAsync(gitArchiveUrl); | ||||
Comment on lines
+365
to
+373
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same, please avoid unnecessary refactors |
||||
|
||||
// Act | ||||
var args = new MigrateRepoCommandArgs | ||||
|
@@ -637,8 +642,10 @@ | |||
_mockEnvironmentVariableProvider.Setup(m => m.TargetGithubPersonalAccessToken(It.IsAny<bool>())).Returns(GITHUB_PAT); | ||||
|
||||
var archiveBytes = Encoding.ASCII.GetBytes("here are some bytes"); | ||||
_mockFileSystemProvider.Setup(x => x.ReadAllBytesAsync(ARCHIVE_PATH)).ReturnsAsync(archiveBytes); | ||||
// Mock file existence check | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||
_mockFileSystemProvider.Setup(x => x.FileExists(ARCHIVE_PATH)).Returns(true); | ||||
|
||||
_mockFileSystemProvider.Setup(x => x.ReadAllBytesAsync(ARCHIVE_PATH)).ReturnsAsync(archiveBytes); | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same, please avoid unnecessary refactors |
||||
_mockAzureApi.Setup(x => x.UploadToBlob(It.IsAny<string>(), It.IsAny<FileStream>())).ReturnsAsync(new Uri(ARCHIVE_URL)); | ||||
|
||||
_mockGithubApi.Setup(x => x.GetOrganizationId(GITHUB_ORG).Result).Returns(GITHUB_ORG_ID); | ||||
|
@@ -670,6 +677,7 @@ | |||
)); | ||||
} | ||||
|
||||
|
||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||
[Fact] | ||||
public async Task Invoke_With_Bbs_Server_Url_Throws_When_Smb_User_Is_Provided_And_Smb_Password_Is_Not_Provided() | ||||
{ | ||||
|
@@ -715,6 +723,9 @@ | |||
// Arrange | ||||
_mockAzureApi.Setup(x => x.UploadToBlob(It.IsAny<string>(), It.IsAny<FileStream>())).ReturnsAsync(new Uri(ARCHIVE_URL)); | ||||
|
||||
// Mock file existence check | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||
_mockFileSystemProvider.Setup(m => m.FileExists(ARCHIVE_PATH)).Returns(true); | ||||
|
||||
// Act | ||||
var args = new MigrateRepoCommandArgs | ||||
{ | ||||
|
@@ -756,11 +767,13 @@ | |||
// Arrange | ||||
_mockEnvironmentVariableProvider.Setup(m => m.TargetGithubPersonalAccessToken(It.IsAny<bool>())).Returns(GITHUB_PAT); | ||||
|
||||
_mockGithubApi.Setup(x => x.GetOrganizationId(GITHUB_ORG).Result).Returns(GITHUB_ORG_ID); | ||||
_mockGithubApi.Setup(x => x.CreateBbsMigrationSource(GITHUB_ORG_ID).Result).Returns(MIGRATION_SOURCE_ID); | ||||
_mockGithubApi.Setup(x => x.GetOrganizationId(GITHUB_ORG)).ReturnsAsync(GITHUB_ORG_ID); | ||||
_mockGithubApi.Setup(x => x.CreateBbsMigrationSource(GITHUB_ORG_ID)).ReturnsAsync(MIGRATION_SOURCE_ID); | ||||
Comment on lines
+770
to
+771
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Solution I used: |
||||
_mockAwsApi.Setup(x => x.UploadToBucket(AWS_BUCKET_NAME, ARCHIVE_PATH, It.IsAny<string>())).ReturnsAsync(ARCHIVE_URL); | ||||
|
||||
// Act | ||||
// Mock the file existence check | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||
_mockFileSystemProvider.Setup(fs => fs.FileExists(ARCHIVE_PATH)).Returns(true); | ||||
|
||||
var args = new MigrateRepoCommandArgs | ||||
{ | ||||
GithubOrg = GITHUB_ORG, | ||||
|
@@ -960,5 +973,60 @@ | |||
targetRepoVisibility | ||||
)); | ||||
} | ||||
[Fact] | ||||
public async Task Does_Not_Throw_Exception_If_BbsSharedHome_Exists() | ||||
{ | ||||
// Arrange | ||||
const string BBS_SHARED_HOME = "valid/path"; | ||||
_mockFileSystemProvider.Setup(x => x.DirectoryExists(BBS_SHARED_HOME)).Returns(true); | ||||
|
||||
var args = new MigrateRepoCommandArgs | ||||
{ | ||||
BbsSharedHome = BBS_SHARED_HOME, | ||||
ArchivePath = string.Empty | ||||
}; | ||||
|
||||
// Act & Assert | ||||
await FluentActions.Invoking(() => _handler.Handle(args)) | ||||
.Should().NotThrowAsync(); | ||||
} | ||||
|
||||
[Fact] | ||||
public async Task Does_Not_Throw_Exception_If_ArchivePath_Exists() | ||||
{ | ||||
// Arrange | ||||
const string ARCHIVE_PATH = "valid/path/to/archive.tar"; | ||||
|
||||
_mockFileSystemProvider.Setup(x => x.FileExists(ARCHIVE_PATH)).Returns(true); | ||||
|
||||
var args = new MigrateRepoCommandArgs | ||||
{ | ||||
ArchivePath = ARCHIVE_PATH | ||||
}; | ||||
|
||||
// Act & Assert | ||||
await FluentActions.Invoking(() => _handler.Handle(args)) | ||||
.Should().NotThrowAsync(); | ||||
} | ||||
|
||||
[Fact] | ||||
public async Task Does_Not_Throw_Exception_If_BbsSharedHome_And_ArchivePath_Are_Both_Valid() | ||||
{ | ||||
// Arrange | ||||
const string BBS_SHARED_HOME = "valid/path"; | ||||
const string ARCHIVE_PATH = "valid/path/to/archive.tar"; | ||||
|
||||
|
||||
_mockFileSystemProvider.Setup(x => x.DirectoryExists(BBS_SHARED_HOME)).Returns(true); | ||||
_mockFileSystemProvider.Setup(x => x.FileExists(ARCHIVE_PATH)).Returns(true); | ||||
|
||||
var args = new MigrateRepoCommandArgs | ||||
{ | ||||
BbsSharedHome = BBS_SHARED_HOME, | ||||
ArchivePath = ARCHIVE_PATH | ||||
}; | ||||
|
||||
// Act & Assert | ||||
await FluentActions.Invoking(() => _handler.Handle(args)) | ||||
.Should().NotThrowAsync(); | ||||
} | ||||
} | ||||
} |
Original file line number | Diff line number | Diff line change | ||||||
---|---|---|---|---|---|---|---|---|
|
@@ -51,7 +51,6 @@ | |||||||
} | ||||||||
|
||||||||
ValidateOptions(args); | ||||||||
|
||||||||
var exportId = 0L; | ||||||||
var migrationSourceId = ""; | ||||||||
|
||||||||
|
@@ -384,5 +383,25 @@ | |||||||
throw new OctoshiftCliException("Either --aws-region or AWS_REGION environment variable must be set."); | ||||||||
} | ||||||||
} | ||||||||
// Validate BbsSharedHome | ||||||||
if (!string.IsNullOrEmpty(args.BbsSharedHome)) | ||||||||
{ | ||||||||
if (args.ArchivePath.IsNullOrWhiteSpace()) // Removed the ShouldUploadArchive Since we are checking it already | ||||||||
{ | ||||||||
if (args.BbsSharedHome.HasValue() && !_fileSystemProvider.DirectoryExists(args.BbsSharedHome)) | ||||||||
{ | ||||||||
throw new OctoshiftCliException($"Invalid --bbs-shared-home path: '{args.BbsSharedHome}'. Directory does not exist."); | ||||||||
} | ||||||||
} | ||||||||
|
||||||||
} | ||||||||
|
||||||||
|
||||||||
// Validate ArchivePath | ||||||||
if (!string.IsNullOrEmpty(args.ArchivePath)) | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit
Suggested change
|
||||||||
{ | ||||||||
if (!_fileSystemProvider.FileExists(args.ArchivePath)) | ||||||||
{ | ||||||||
throw new OctoshiftCliException($"Invalid --archive-path: '{args.ArchivePath}'. File does not exist."); | ||||||||
} | ||||||||
} | ||||||||
|
||||||||
} | ||||||||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please avoid doing any refactors in this PR to keep the scope of changes as small as possible.