8
8
using Octoshift . Models ;
9
9
using OctoshiftCLI . Contracts ;
10
10
using OctoshiftCLI . Extensions ;
11
- using OctoshiftCLI . GithubEnterpriseImporter ;
12
11
using OctoshiftCLI . GithubEnterpriseImporter . Commands ;
13
12
using OctoshiftCLI . GithubEnterpriseImporter . Handlers ;
14
13
using Xunit ;
@@ -19,7 +18,6 @@ public class GenerateScriptCommandHandlerTests
19
18
{
20
19
private readonly Mock < GithubApi > _mockGithubApi = TestHelpers . CreateMock < GithubApi > ( ) ;
21
20
private readonly Mock < AdoApi > _mockAdoApi = TestHelpers . CreateMock < AdoApi > ( ) ;
22
- private readonly Mock < EnvironmentVariableProvider > _mockEnvironmentVariableProvider = TestHelpers . CreateMock < EnvironmentVariableProvider > ( ) ;
23
21
private readonly Mock < OctoLogger > _mockOctoLogger = TestHelpers . CreateMock < OctoLogger > ( ) ;
24
22
private readonly Mock < IVersionProvider > _mockVersionProvider = new Mock < IVersionProvider > ( ) ;
25
23
@@ -28,6 +26,7 @@ public class GenerateScriptCommandHandlerTests
28
26
private const string SOURCE_ORG = "FOO-SOURCE-ORG" ;
29
27
private const string TARGET_ORG = "FOO-TARGET-ORG" ;
30
28
private const string REPO = "REPO" ;
29
+ private const string AWS_BUCKET_NAME = "AWS_BUCKET_NAME" ;
31
30
private string _script ;
32
31
33
32
public GenerateScriptCommandHandlerTests ( )
@@ -36,7 +35,6 @@ public GenerateScriptCommandHandlerTests()
36
35
_mockOctoLogger . Object ,
37
36
_mockGithubApi . Object ,
38
37
_mockAdoApi . Object ,
39
- _mockEnvironmentVariableProvider . Object ,
40
38
_mockVersionProvider . Object
41
39
)
42
40
{
@@ -61,6 +59,14 @@ await FluentActions
61
59
. Should ( ) . ThrowAsync < OctoshiftCliException > ( ) ;
62
60
}
63
61
62
+ [ Fact ]
63
+ public async Task No_Github_Source_Org_Or_Ado_Source_Org_Throws ( )
64
+ {
65
+ await _handler . Invoking ( async handler => await handler . Handle ( new GenerateScriptCommandArgs { GithubTargetOrg = TARGET_ORG } ) )
66
+ . Should ( )
67
+ . ThrowAsync < OctoshiftCliException > ( ) ;
68
+ }
69
+
64
70
[ Fact ]
65
71
public async Task Sequential_Github_No_Data ( )
66
72
{
@@ -295,13 +301,12 @@ public async Task Sequential_Github_Ghes_Repo()
295
301
{
296
302
// Arrange
297
303
const string ghesApiUrl = "https://foo.com/api/v3" ;
298
- const string azureStorageConnectionString = "FOO-STORAGE-CONNECTION-STRING" ;
299
304
300
305
_mockGithubApi
301
306
. Setup ( m => m . GetRepos ( SOURCE_ORG ) )
302
307
. ReturnsAsync ( new [ ] { REPO } ) ;
303
308
304
- 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 } \" --azure-storage-connection-string \" { azureStorageConnectionString } \" -- wait }}";
309
+ 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 } \" --wait }}";
305
310
306
311
// Act
307
312
var args = new GenerateScriptCommandArgs
@@ -310,7 +315,6 @@ public async Task Sequential_Github_Ghes_Repo()
310
315
GithubTargetOrg = TARGET_ORG ,
311
316
Output = new FileInfo ( "unit-test-output" ) ,
312
317
GhesApiUrl = ghesApiUrl ,
313
- AzureStorageConnectionString = azureStorageConnectionString ,
314
318
Sequential = true
315
319
} ;
316
320
await _handler . Handle ( args ) ;
@@ -319,7 +323,6 @@ public async Task Sequential_Github_Ghes_Repo()
319
323
320
324
// Assert
321
325
_script . Should ( ) . Be ( expected ) ;
322
- _mockOctoLogger . Verify ( m => m . LogInformation ( "AZURE STORAGE CONNECTION STRING: ***" ) ) ;
323
326
_mockOctoLogger . Verify ( m => m . LogInformation ( $ "GHES API URL: { ghesApiUrl } ") ) ;
324
327
}
325
328
@@ -658,7 +661,6 @@ public async Task Parallel_Github_Ghes_Single_Repo()
658
661
{
659
662
// Arrange
660
663
const string ghesApiUrl = "https://foo.com/api/v3" ;
661
- const string azureStorageConnectionString = "FOO-STORAGE-CONNECTION-STRING" ;
662
664
663
665
_mockGithubApi
664
666
. Setup ( m => m . GetRepos ( SOURCE_ORG ) )
@@ -699,7 +701,7 @@ function ExecAndGetMigrationID {
699
701
expected . AppendLine ( $ "# =========== Organization: { SOURCE_ORG } ===========") ;
700
702
expected . AppendLine ( ) ;
701
703
expected . AppendLine ( "# === Queuing repo migrations ===" ) ;
702
- expected . AppendLine ( $ "$MigrationID = ExecAndGetMigrationID {{ gh gei migrate-repo --github-source-org \" { SOURCE_ORG } \" --source-repo \" { REPO } \" --github-target-org \" { TARGET_ORG } \" --target-repo \" { REPO } \" --ghes-api-url \" { ghesApiUrl } \" --azure-storage-connection-string \" { azureStorageConnectionString } \" }}") ;
704
+ expected . AppendLine ( $ "$MigrationID = ExecAndGetMigrationID {{ gh gei migrate-repo --github-source-org \" { SOURCE_ORG } \" --source-repo \" { REPO } \" --github-target-org \" { TARGET_ORG } \" --target-repo \" { REPO } \" --ghes-api-url \" { ghesApiUrl } \" }}") ;
703
705
expected . AppendLine ( $ "$RepoMigrations[\" { REPO } \" ] = $MigrationID") ;
704
706
expected . AppendLine ( ) ;
705
707
expected . AppendLine ( ) ;
@@ -725,14 +727,12 @@ exit 1
725
727
GithubSourceOrg = SOURCE_ORG ,
726
728
GithubTargetOrg = TARGET_ORG ,
727
729
Output = new FileInfo ( "unit-test-output" ) ,
728
- GhesApiUrl = ghesApiUrl ,
729
- AzureStorageConnectionString = azureStorageConnectionString
730
+ GhesApiUrl = ghesApiUrl
730
731
} ;
731
732
await _handler . Handle ( args ) ;
732
733
733
734
// Assert
734
735
_script . Should ( ) . Be ( expected . ToString ( ) ) ;
735
- _mockOctoLogger . Verify ( m => m . LogInformation ( "AZURE STORAGE CONNECTION STRING: ***" ) ) ;
736
736
_mockOctoLogger . Verify ( m => m . LogInformation ( $ "GHES API URL: { ghesApiUrl } ") ) ;
737
737
}
738
738
@@ -1026,7 +1026,6 @@ public async Task Parallel_Github_Ghes_Single_Repo_With_Download_Migration_Logs(
1026
1026
{
1027
1027
// Arrange
1028
1028
const string ghesApiUrl = "https://foo.com/api/v3" ;
1029
- const string azureStorageConnectionString = "FOO-STORAGE-CONNECTION-STRING" ;
1030
1029
1031
1030
_mockGithubApi
1032
1031
. Setup ( m => m . GetRepos ( SOURCE_ORG ) )
@@ -1067,7 +1066,7 @@ function ExecAndGetMigrationID {
1067
1066
expected . AppendLine ( $ "# =========== Organization: { SOURCE_ORG } ===========") ;
1068
1067
expected . AppendLine ( ) ;
1069
1068
expected . AppendLine ( "# === Queuing repo migrations ===" ) ;
1070
- expected . AppendLine ( $ "$MigrationID = ExecAndGetMigrationID {{ gh gei migrate-repo --github-source-org \" { SOURCE_ORG } \" --source-repo \" { REPO } \" --github-target-org \" { TARGET_ORG } \" --target-repo \" { REPO } \" --ghes-api-url \" { ghesApiUrl } \" --azure-storage-connection-string \" { azureStorageConnectionString } \" }}") ;
1069
+ expected . AppendLine ( $ "$MigrationID = ExecAndGetMigrationID {{ gh gei migrate-repo --github-source-org \" { SOURCE_ORG } \" --source-repo \" { REPO } \" --github-target-org \" { TARGET_ORG } \" --target-repo \" { REPO } \" --ghes-api-url \" { ghesApiUrl } \" }}") ;
1071
1070
expected . AppendLine ( $ "$RepoMigrations[\" { REPO } \" ] = $MigrationID") ;
1072
1071
expected . AppendLine ( ) ;
1073
1072
expected . AppendLine ( ) ;
@@ -1095,7 +1094,6 @@ exit 1
1095
1094
GithubTargetOrg = TARGET_ORG ,
1096
1095
Output = new FileInfo ( "unit-test-output" ) ,
1097
1096
GhesApiUrl = ghesApiUrl ,
1098
- AzureStorageConnectionString = azureStorageConnectionString ,
1099
1097
DownloadMigrationLogs = true
1100
1098
} ;
1101
1099
await _handler . Handle ( args ) ;
@@ -1109,7 +1107,6 @@ public async Task Parallel_Github_Ghes_Single_Repo_No_Ssl()
1109
1107
{
1110
1108
// Arrange
1111
1109
const string ghesApiUrl = "https://foo.com/api/v3" ;
1112
- const string azureStorageConnectionString = "FOO-STORAGE-CONNECTION-STRING" ;
1113
1110
1114
1111
_mockGithubApi
1115
1112
. Setup ( m => m . GetRepos ( SOURCE_ORG ) )
@@ -1150,7 +1147,7 @@ function ExecAndGetMigrationID {
1150
1147
expected . AppendLine ( $ "# =========== Organization: { SOURCE_ORG } ===========") ;
1151
1148
expected . AppendLine ( ) ;
1152
1149
expected . AppendLine ( "# === Queuing repo migrations ===" ) ;
1153
- expected . AppendLine ( $ "$MigrationID = ExecAndGetMigrationID {{ gh gei migrate-repo --github-source-org \" { SOURCE_ORG } \" --source-repo \" { REPO } \" --github-target-org \" { TARGET_ORG } \" --target-repo \" { REPO } \" --ghes-api-url \" { ghesApiUrl } \" --azure-storage-connection-string \" { azureStorageConnectionString } \" -- no-ssl-verify }}") ;
1150
+ expected . AppendLine ( $ "$MigrationID = ExecAndGetMigrationID {{ gh gei migrate-repo --github-source-org \" { SOURCE_ORG } \" --source-repo \" { REPO } \" --github-target-org \" { TARGET_ORG } \" --target-repo \" { REPO } \" --ghes-api-url \" { ghesApiUrl } \" --no-ssl-verify }}") ;
1154
1151
expected . AppendLine ( $ "$RepoMigrations[\" { REPO } \" ] = $MigrationID") ;
1155
1152
expected . AppendLine ( ) ;
1156
1153
expected . AppendLine ( ) ;
@@ -1177,7 +1174,6 @@ exit 1
1177
1174
GithubTargetOrg = TARGET_ORG ,
1178
1175
Output = new FileInfo ( "unit-test-output" ) ,
1179
1176
GhesApiUrl = ghesApiUrl ,
1180
- AzureStorageConnectionString = azureStorageConnectionString ,
1181
1177
NoSslVerify = true
1182
1178
} ;
1183
1179
await _handler . Handle ( args ) ;
@@ -1402,6 +1398,77 @@ public async Task Parallel_Ado_Contains_Cli_Version()
1402
1398
_script . Should ( ) . Contain ( expectedCliVersionComment ) ;
1403
1399
}
1404
1400
1401
+ [ Fact ]
1402
+ public async Task Sequential_Ghes_Single_Repo_Aws_S3 ( )
1403
+ {
1404
+ // Arrange
1405
+ const string ghesApiUrl = "https://foo.com/api/v3" ;
1406
+
1407
+ _mockGithubApi
1408
+ . Setup ( m => m . GetRepos ( SOURCE_ORG ) )
1409
+ . ReturnsAsync ( new [ ] { REPO } ) ;
1410
+
1411
+ 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 } \" --wait }}";
1412
+
1413
+ // Act
1414
+ var args = new GenerateScriptCommandArgs
1415
+ {
1416
+ GithubSourceOrg = SOURCE_ORG ,
1417
+ GithubTargetOrg = TARGET_ORG ,
1418
+ Output = new FileInfo ( "unit-test-output" ) ,
1419
+ GhesApiUrl = ghesApiUrl ,
1420
+ AwsBucketName = AWS_BUCKET_NAME ,
1421
+ Sequential = true
1422
+ } ;
1423
+ await _handler . Handle ( args ) ;
1424
+
1425
+ _script = TrimNonExecutableLines ( _script ) ;
1426
+
1427
+ // Assert
1428
+ _script . Should ( ) . Be ( expected ) ;
1429
+ _mockOctoLogger . Verify ( m => m . LogInformation ( $ "AWS BUCKET NAME: { AWS_BUCKET_NAME } ") ) ;
1430
+ }
1431
+
1432
+ [ Fact ]
1433
+ public async Task It_Throws_When_Aws_Bucket_Name_Is_Provided_But_Ghes_Api_Url_Is_Not ( )
1434
+ {
1435
+ // Arrange
1436
+ var args = new GenerateScriptCommandArgs
1437
+ {
1438
+ GithubSourceOrg = SOURCE_ORG ,
1439
+ GithubTargetOrg = TARGET_ORG ,
1440
+ Output = new FileInfo ( "unit-test-output" ) ,
1441
+ AwsBucketName = AWS_BUCKET_NAME ,
1442
+ Sequential = true
1443
+ } ;
1444
+
1445
+ // Act, Assert
1446
+ await _handler
1447
+ . Invoking ( async handler => await handler . Handle ( args ) )
1448
+ . Should ( )
1449
+ . ThrowAsync < OctoshiftCliException > ( ) ;
1450
+ }
1451
+
1452
+ [ Fact ]
1453
+ public async Task It_Throws_When_No_Ssl_Verify_Is_Set_But_Ghes_Api_Url_Is_Not ( )
1454
+ {
1455
+ // Arrange
1456
+ var args = new GenerateScriptCommandArgs
1457
+ {
1458
+ GithubSourceOrg = SOURCE_ORG ,
1459
+ GithubTargetOrg = TARGET_ORG ,
1460
+ Output = new FileInfo ( "unit-test-output" ) ,
1461
+ NoSslVerify = true ,
1462
+ Sequential = true
1463
+ } ;
1464
+
1465
+ // Act, Assert
1466
+ await _handler
1467
+ . Invoking ( async handler => await handler . Handle ( args ) )
1468
+ . Should ( )
1469
+ . ThrowAsync < OctoshiftCliException > ( ) ;
1470
+ }
1471
+
1405
1472
private string TrimNonExecutableLines ( string script , int skipFirst = 9 , int skipLast = 0 )
1406
1473
{
1407
1474
var lines = script . Split ( new [ ] { Environment . NewLine , "\n " } , StringSplitOptions . RemoveEmptyEntries ) . AsEnumerable ( ) ;
0 commit comments