Skip to content

Commit 2c1ea1c

Browse files
committed
Add test case for CreateTeams with TargetApiUrl integration
Verify that when both CreateTeams and TargetApiUrl options are set, the generated script includes --target-api-url in the add-team-to-repo commands. This ensures proper integration when migrating to GHE.com.
1 parent 1a7dac2 commit 2c1ea1c

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

src/OctoshiftCLI.Tests/ado2gh/Commands/GenerateScript/GenerateScriptCommandHandlerTests.cs

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1331,6 +1331,42 @@ public async Task ParallelScript_Rewire_Pipelines_Option_Should_Generate_Share_S
13311331
_scriptOutput.Should().Be(expected.ToString());
13321332
}
13331333

1334+
[Fact]
1335+
public async Task SequentialScript_CreateTeams_With_TargetApiUrl_Should_Include_TargetApiUrl_In_AddTeamToRepo_Commands()
1336+
{
1337+
// Arrange
1338+
const string TARGET_API_URL = "https://example.com/api/v3";
1339+
1340+
_mockAdoInspector.Setup(m => m.GetRepoCount()).ReturnsAsync(1);
1341+
_mockAdoInspector.Setup(m => m.GetOrgs()).ReturnsAsync(ADO_ORGS);
1342+
_mockAdoInspector.Setup(m => m.GetTeamProjects(ADO_ORG)).ReturnsAsync(ADO_TEAM_PROJECTS);
1343+
_mockAdoInspector.Setup(m => m.GetRepos(ADO_ORG, ADO_TEAM_PROJECT)).ReturnsAsync(ADO_REPOS);
1344+
1345+
var expected = new StringBuilder();
1346+
expected.AppendLine($"Exec {{ gh ado2gh create-team --target-api-url \"{TARGET_API_URL}\" --github-org \"{GITHUB_ORG}\" --team-name \"{ADO_TEAM_PROJECT}-Maintainers\" }}");
1347+
expected.AppendLine($"Exec {{ gh ado2gh create-team --target-api-url \"{TARGET_API_URL}\" --github-org \"{GITHUB_ORG}\" --team-name \"{ADO_TEAM_PROJECT}-Admins\" }}");
1348+
expected.AppendLine($"Exec {{ gh ado2gh migrate-repo --target-api-url \"{TARGET_API_URL}\" --ado-org \"{ADO_ORG}\" --ado-team-project \"{ADO_TEAM_PROJECT}\" --ado-repo \"{FOO_REPO}\" --github-org \"{GITHUB_ORG}\" --github-repo \"{ADO_TEAM_PROJECT}-{FOO_REPO}\" --target-repo-visibility private }}");
1349+
expected.AppendLine($"Exec {{ gh ado2gh add-team-to-repo --target-api-url \"{TARGET_API_URL}\" --github-org \"{GITHUB_ORG}\" --github-repo \"{ADO_TEAM_PROJECT}-{FOO_REPO}\" --team \"{ADO_TEAM_PROJECT}-Maintainers\" --role \"maintain\" }}");
1350+
expected.Append($"Exec {{ gh ado2gh add-team-to-repo --target-api-url \"{TARGET_API_URL}\" --github-org \"{GITHUB_ORG}\" --github-repo \"{ADO_TEAM_PROJECT}-{FOO_REPO}\" --team \"{ADO_TEAM_PROJECT}-Admins\" --role \"admin\" }}");
1351+
1352+
// Act
1353+
var args = new GenerateScriptCommandArgs
1354+
{
1355+
GithubOrg = GITHUB_ORG,
1356+
AdoOrg = ADO_ORG,
1357+
Sequential = true,
1358+
Output = new FileInfo("unit-test-output"),
1359+
CreateTeams = true,
1360+
TargetApiUrl = TARGET_API_URL
1361+
};
1362+
await _handler.Handle(args);
1363+
1364+
_scriptOutput = TrimNonExecutableLines(_scriptOutput);
1365+
1366+
// Assert
1367+
_scriptOutput.Should().Be(expected.ToString());
1368+
}
1369+
13341370
private string TrimNonExecutableLines(string script, int skipFirst = 21, int skipLast = 0)
13351371
{
13361372
var lines = script.Split(new[] { Environment.NewLine, "\n" }, StringSplitOptions.RemoveEmptyEntries).AsEnumerable();

0 commit comments

Comments
 (0)