-
Notifications
You must be signed in to change notification settings - Fork 136
Provides a mechanism to "lock" a source GH repo (#2) #424
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
Closed
Closed
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
9ea74c1
Provides a mechanism to "lock" a source GH repo (#2)
tj-cappelletti f65c8fe
Merge branch 'main' into main
pmartindev 4da6c65
Merge branch 'main' of github.com:github/gh-gei into github-main
9f6bcd0
Merge branch 'github-main' into main
b79a85d
Merge branch 'main' of github.com:github/gh-gei into github-main
82b58b6
Merge branch 'github-main' into main
tj-cappelletti 36174e7
Added Archive Repo Command (#4)
tj-cappelletti e30c072
Optimized code to address CodeQL issues
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
114 changes: 114 additions & 0 deletions
114
src/OctoshiftCLI.Tests/gei/Commands/ArchiveGitHubRepoCommandTests.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,114 @@ | ||
| using System; | ||
| using System.Threading.Tasks; | ||
| using FluentAssertions; | ||
| using Moq; | ||
| using OctoshiftCLI.GithubEnterpriseImporter; | ||
| using OctoshiftCLI.GithubEnterpriseImporter.Commands; | ||
| using Xunit; | ||
|
|
||
| // ReSharper disable once CheckNamespace | ||
| namespace OctoshiftCLI.Tests.GithubEnterpriseImporter.Commands; | ||
|
|
||
| public class ArchiveGitHubRepoCommandTests | ||
| { | ||
| public ArchiveGitHubRepoCommandTests() => | ||
| _command = new ArchiveGitHubRepoCommand( | ||
| _mockOctoLogger.Object, | ||
| _mockSourceGithubApiFactory.Object, | ||
| _mockEnvironmentVariableProvider.Object); | ||
|
|
||
| private readonly Mock<GithubApi> _mockGithubApi = TestHelpers.CreateMock<GithubApi>(); | ||
| private readonly Mock<ISourceGithubApiFactory> _mockSourceGithubApiFactory = new(); | ||
| private readonly Mock<EnvironmentVariableProvider> _mockEnvironmentVariableProvider = TestHelpers.CreateMock<EnvironmentVariableProvider>(); | ||
| private readonly Mock<OctoLogger> _mockOctoLogger = TestHelpers.CreateMock<OctoLogger>(); | ||
| private readonly ArchiveGitHubRepoCommand _command; | ||
|
|
||
| [Fact] | ||
| public async Task Happy_Path_For_Ghec() | ||
| { | ||
| var sourceOrg = Guid.NewGuid().ToString(); | ||
| var sourceRepo = Guid.NewGuid().ToString(); | ||
| var sourceGithubPat = Guid.NewGuid().ToString(); | ||
|
|
||
| _mockGithubApi.Setup(_ => _.ArchiveRepository(sourceOrg, sourceRepo)).Verifiable("`ArchiveRepository` call did not match specifications"); | ||
|
|
||
| _mockSourceGithubApiFactory | ||
| .Setup(_ => _.Create(null, sourceGithubPat)) | ||
| .Returns(_mockGithubApi.Object); | ||
|
|
||
| var args = new ArchiveGitHubRepoCommandArgs | ||
| { | ||
| GithubSourceOrg = sourceOrg, | ||
| GithubSourcePat = sourceGithubPat, | ||
| SourceRepo = sourceRepo | ||
| }; | ||
|
|
||
| await _command.Invoke(args); | ||
| } | ||
|
|
||
| [Fact] | ||
| public async Task Happy_Path_For_Ghes() | ||
| { | ||
| var ghesApiUrl = "https://myghes.local/api/v3"; | ||
| var sourceOrg = Guid.NewGuid().ToString(); | ||
| var sourceRepo = Guid.NewGuid().ToString(); | ||
| var sourceGithubPat = Guid.NewGuid().ToString(); | ||
|
|
||
| _mockGithubApi.Setup(_ => _.ArchiveRepository(sourceOrg, sourceRepo)).Verifiable("`ArchiveRepository` call did not match specifications"); | ||
|
|
||
| _mockSourceGithubApiFactory | ||
| .Setup(_ => _.Create(ghesApiUrl, sourceGithubPat)) | ||
| .Returns(_mockGithubApi.Object); | ||
|
|
||
| var args = new ArchiveGitHubRepoCommandArgs | ||
| { | ||
| GhesApiUrl = ghesApiUrl, | ||
| GithubSourceOrg = sourceOrg, | ||
| GithubSourcePat = sourceGithubPat, | ||
| SourceRepo = sourceRepo | ||
| }; | ||
|
|
||
| await _command.Invoke(args); | ||
| } | ||
|
|
||
| [Fact] | ||
| public async Task Happy_Path_For_Ghes_With_No_Ssl_Verify() | ||
| { | ||
| var ghesApiUrl = "https://myghes.local/api/v3"; | ||
| var sourceOrg = Guid.NewGuid().ToString(); | ||
| var sourceRepo = Guid.NewGuid().ToString(); | ||
| var sourceGithubPat = Guid.NewGuid().ToString(); | ||
|
|
||
| _mockGithubApi.Setup(_ => _.ArchiveRepository(sourceOrg, sourceRepo)).Verifiable("`ArchiveRepository` call did not match specifications"); | ||
|
|
||
| _mockSourceGithubApiFactory | ||
| .Setup(_ => _.CreateClientNoSsl(ghesApiUrl, sourceGithubPat)) | ||
| .Returns(_mockGithubApi.Object); | ||
|
|
||
| var args = new ArchiveGitHubRepoCommandArgs | ||
| { | ||
| GhesApiUrl = ghesApiUrl, | ||
| GithubSourceOrg = sourceOrg, | ||
| GithubSourcePat = sourceGithubPat, | ||
| SourceRepo = sourceRepo, | ||
| NoSslVerify = true | ||
| }; | ||
|
|
||
| await _command.Invoke(args); | ||
| } | ||
|
|
||
| [Fact] | ||
| public void Should_Have_Options() | ||
| { | ||
| _command.Should().NotBeNull(); | ||
| _command.Name.Should().Be("archive-gh-repo"); | ||
| _command.Options.Count.Should().Be(6); | ||
|
|
||
| TestHelpers.VerifyCommandOption(_command.Options, "github-source-org", true); | ||
| TestHelpers.VerifyCommandOption(_command.Options, "github-source-pat", false); | ||
| TestHelpers.VerifyCommandOption(_command.Options, "source-repo", true); | ||
| TestHelpers.VerifyCommandOption(_command.Options, "ghes-api-url", false); | ||
| TestHelpers.VerifyCommandOption(_command.Options, "no-ssl-verify", false); | ||
| TestHelpers.VerifyCommandOption(_command.Options, "verbose", false); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Check notice
Code scanning / CodeQL
Redundant ToString() call