1+ using System ;
2+ using System . Collections . Generic ;
3+ using System . IO ;
4+ using System . Net . Http ;
5+ using System . Threading . Tasks ;
6+ using Azure . Storage . Blobs ;
7+ using OctoshiftCLI . Services ;
8+ using Xunit ;
9+ using Xunit . Abstractions ;
10+
11+ namespace OctoshiftCLI . IntegrationTests ;
12+
13+ [ Collection ( "Integration Tests" ) ]
14+ public sealed class BbsAwsLinuxToGithub : IDisposable
15+ {
16+ private const string SSH_KEY_FILE = "ssh_key.pem" ;
17+ private const string AWS_REGION = "us-east-1" ;
18+
19+ private readonly ITestOutputHelper _output ;
20+ private readonly OctoLogger _logger ;
21+ private readonly TestHelper _targetHelper ;
22+ private readonly HttpClient _versionClient ;
23+ private readonly HttpClient _targetGithubHttpClient ;
24+ private readonly GithubClient _targetGithubClient ;
25+ private readonly GithubApi _targetGithubApi ;
26+ private readonly HttpClient _sourceBbsHttpClient ;
27+ private readonly BbsClient _sourceBbsClient ;
28+ private readonly BlobServiceClient _blobServiceClient ;
29+ private readonly ArchiveUploader _archiveUploader ;
30+ private readonly Dictionary < string , string > _tokens ;
31+ private readonly DateTime _startTime ;
32+
33+ public BbsAwsLinuxToGithub ( ITestOutputHelper output )
34+ {
35+ _startTime = DateTime . Now ;
36+ _output = output ;
37+
38+ _logger = new OctoLogger ( _ => { } , x => _output . WriteLine ( x ) , _ => { } , _ => { } ) ;
39+
40+ var sourceBbsUsername = Environment . GetEnvironmentVariable ( "BBS_USERNAME" ) ;
41+ var sourceBbsPassword = Environment . GetEnvironmentVariable ( "BBS_PASSWORD" ) ;
42+ var targetGithubToken = Environment . GetEnvironmentVariable ( "GHEC_PAT" ) ;
43+ _tokens = new Dictionary < string , string >
44+ {
45+ [ "GHEC_PAT" ] = targetGithubToken ,
46+ [ "BBS_USERNAME" ] = sourceBbsUsername ,
47+ [ "BBS_PASSWORD" ] = sourceBbsPassword
48+ } ;
49+
50+ _targetHelper = new TestHelper ( _output , targetGithubToken ) ;
51+
52+ _versionClient = new HttpClient ( ) ;
53+ _targetGithubHttpClient = new HttpClient ( ) ;
54+ _targetGithubClient = new GithubClient ( _logger , _targetGithubHttpClient , new VersionChecker ( _versionClient , _logger ) , new RetryPolicy ( _logger ) , new DateTimeProvider ( ) , targetGithubToken ) ;
55+ var retryPolicy = new RetryPolicy ( _logger ) ;
56+ var environmentVariableProvider = new EnvironmentVariableProvider ( _logger ) ;
57+ _archiveUploader = new ArchiveUploader ( _targetGithubClient , _logger , retryPolicy , environmentVariableProvider ) ;
58+ _targetGithubApi = new GithubApi ( _targetGithubClient , "https://api.github.com" , new RetryPolicy ( _logger ) , _archiveUploader ) ;
59+
60+ var azureStorageConnectionString = Environment . GetEnvironmentVariable ( $ "AZURE_STORAGE_CONNECTION_STRING_BBS_{ TestHelper . GetOsName ( ) . ToUpper ( ) } ") ;
61+ _blobServiceClient = new BlobServiceClient ( azureStorageConnectionString ) ;
62+
63+ _sourceBbsHttpClient = new HttpClient ( ) ;
64+ _sourceBbsClient = new BbsClient ( _logger , _sourceBbsHttpClient , new VersionChecker ( _versionClient , _logger ) , new RetryPolicy ( _logger ) , new DateTimeProvider ( ) , sourceBbsUsername , sourceBbsPassword ) ;
65+ }
66+
67+ [ Fact ]
68+ public async Task MigrateRepo_BbsLinux_AwsS3 ( )
69+ {
70+ var bbsServer = "http://e2e-bbs-8-5-0-linux-2204.westus2.cloudapp.azure.com:7990" ;
71+ var bbsProjectKey = $ "E2E-{ TestHelper . GetOsName ( ) . ToUpper ( ) } ";
72+ var githubTargetOrg = $ "octoshift-e2e-bbs-{ TestHelper . GetOsName ( ) } ";
73+ var repo1 = $ "{ bbsProjectKey } -repo-1";
74+ var repo2 = $ "{ bbsProjectKey } -repo-2";
75+ var targetRepo1 = $ "{ bbsProjectKey } -e2e-{ TestHelper . GetOsName ( ) . ToLower ( ) } -repo-1";
76+ var targetRepo2 = $ "{ bbsProjectKey } -e2e-{ TestHelper . GetOsName ( ) . ToLower ( ) } -repo-2";
77+
78+ var sourceBbsApi = new BbsApi ( _sourceBbsClient , bbsServer , _logger ) ;
79+ var sourceHelper = new TestHelper ( _output , sourceBbsApi , _sourceBbsClient , bbsServer ) ;
80+
81+ var retryPolicy = new RetryPolicy ( null ) ;
82+
83+ await retryPolicy . Retry ( async ( ) =>
84+ {
85+ await _targetHelper . ResetBlobContainers ( ) ;
86+ await sourceHelper . ResetBbsTestEnvironment ( bbsProjectKey ) ;
87+ await _targetHelper . ResetGithubTestEnvironment ( githubTargetOrg ) ;
88+
89+ await sourceHelper . CreateBbsProject ( bbsProjectKey ) ;
90+ await sourceHelper . CreateBbsRepo ( bbsProjectKey , repo1 ) ;
91+ await sourceHelper . InitializeBbsRepo ( bbsProjectKey , repo1 ) ;
92+ await sourceHelper . CreateBbsRepo ( bbsProjectKey , repo2 ) ;
93+ await sourceHelper . InitializeBbsRepo ( bbsProjectKey , repo2 ) ;
94+ } ) ;
95+
96+ // Use SSH for archive download
97+ var sshKey = Environment . GetEnvironmentVariable ( "SSH_KEY_BBS_8_5_0" ) ;
98+ await File . WriteAllTextAsync ( Path . Join ( TestHelper . GetOsDistPath ( ) , SSH_KEY_FILE ) , sshKey ) ;
99+ var archiveDownloadOptions = $ " --ssh-user octoshift --ssh-private-key { SSH_KEY_FILE } ";
100+
101+ // Use AWS S3
102+ _tokens . Add ( "AWS_ACCESS_KEY_ID" , Environment . GetEnvironmentVariable ( "AWS_ACCESS_KEY_ID" ) ) ;
103+ _tokens . Add ( "AWS_SECRET_ACCESS_KEY" , Environment . GetEnvironmentVariable ( "AWS_SECRET_ACCESS_KEY" ) ) ;
104+ var awsBucketName = Environment . GetEnvironmentVariable ( "AWS_BUCKET_NAME" ) ;
105+ var awsOptions = $ " --aws-bucket-name { awsBucketName } --aws-region { AWS_REGION } ";
106+
107+ await _targetHelper . RunBbsCliMigration (
108+ $ "migrate-repo --github-org { githubTargetOrg } --bbs-server-url { bbsServer } --bbs-project { bbsProjectKey } --bbs-repo { repo1 } --github-repo { targetRepo1 } { archiveDownloadOptions } { awsOptions } ", _tokens ) ;
109+
110+ _targetHelper . AssertNoErrorInLogs ( _startTime ) ;
111+
112+ await _targetHelper . AssertGithubRepoExists ( githubTargetOrg , targetRepo1 ) ;
113+ await _targetHelper . AssertGithubRepoInitialized ( githubTargetOrg , targetRepo1 ) ;
114+
115+ await _targetHelper . RunBbsCliMigration (
116+ $ "migrate-repo --github-org { githubTargetOrg } --bbs-server-url { bbsServer } --bbs-project { bbsProjectKey } --bbs-repo { repo2 } --github-repo { targetRepo2 } { archiveDownloadOptions } { awsOptions } ", _tokens ) ;
117+
118+ _targetHelper . AssertNoErrorInLogs ( _startTime ) ;
119+
120+ await _targetHelper . AssertGithubRepoExists ( githubTargetOrg , targetRepo2 ) ;
121+ await _targetHelper . AssertGithubRepoInitialized ( githubTargetOrg , targetRepo2 ) ;
122+ }
123+
124+ public void Dispose ( )
125+ {
126+ _sourceBbsHttpClient ? . Dispose ( ) ;
127+ _targetGithubHttpClient ? . Dispose ( ) ;
128+ _versionClient ? . Dispose ( ) ;
129+ }
130+ }
0 commit comments