-
Notifications
You must be signed in to change notification settings - Fork 136
Expand file tree
/
Copy pathGithubToGithub.cs
More file actions
95 lines (78 loc) · 3.56 KB
/
GithubToGithub.cs
File metadata and controls
95 lines (78 loc) · 3.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
using System;
using System.Collections.Generic;
using System.Net.Http;
using System.Threading.Tasks;
using OctoshiftCLI.Services;
using Xunit;
using Xunit.Abstractions;
namespace OctoshiftCLI.IntegrationTests
{
[Collection("Integration Tests")]
public class GithubToGithub : IDisposable
{
private readonly ITestOutputHelper _output;
private readonly GithubApi _githubApi;
private readonly TestHelper _helper;
private readonly HttpClient _githubHttpClient;
private readonly HttpClient _versionClient;
private readonly GithubClient _githubClient;
private bool disposedValue;
private readonly Dictionary<string, string> _tokens;
private readonly DateTime _startTime;
public GithubToGithub(ITestOutputHelper output)
{
_startTime = DateTime.Now;
_output = output;
var logger = new OctoLogger(x => { }, x => _output.WriteLine(x), x => { }, x => { });
var githubToken = Environment.GetEnvironmentVariable("GHEC_PAT");
_tokens = new Dictionary<string, string> { ["GH_PAT"] = githubToken };
_githubHttpClient = new HttpClient();
_versionClient = new HttpClient();
_githubClient = new GithubClient(logger, _githubHttpClient, new VersionChecker(_versionClient, logger), new RetryPolicy(logger, "GitHub (GHEC_PAT)"), new DateTimeProvider(), githubToken);
_githubApi = new GithubApi(_githubClient, "https://api.github.com", new RetryPolicy(logger, "GitHub (GHEC_PAT)"), null);
_helper = new TestHelper(_output, _githubApi, _githubClient);
}
[Fact]
public async Task Basic()
{
var githubSourceOrg = $"octoshift-e2e-source-{TestHelper.GetOsName()}";
var githubTargetOrg = $"octoshift-e2e-ghec-{TestHelper.GetOsName()}";
var repo1 = "repo-1";
var repo2 = "repo-2";
var retryPolicy = new RetryPolicy(null);
await retryPolicy.Retry(async () =>
{
await _helper.ResetGithubTestEnvironment(githubSourceOrg);
await _helper.ResetGithubTestEnvironment(githubTargetOrg);
await _helper.CreateGithubRepo(githubSourceOrg, repo1);
await _helper.CreateGithubRepo(githubSourceOrg, repo2);
});
await _helper.RunGeiCliMigration($"generate-script --github-source-org {githubSourceOrg} --github-target-org {githubTargetOrg} --download-migration-logs", _tokens);
_helper.AssertNoErrorInLogs(_startTime);
await _helper.AssertGithubRepoExists(githubTargetOrg, repo1);
await _helper.AssertGithubRepoExists(githubTargetOrg, repo2);
await _helper.AssertGithubRepoInitialized(githubTargetOrg, repo1);
await _helper.AssertGithubRepoInitialized(githubTargetOrg, repo2);
_helper.AssertMigrationLogFileExists(githubTargetOrg, repo1);
_helper.AssertMigrationLogFileExists(githubTargetOrg, repo2);
}
protected virtual void Dispose(bool disposing)
{
if (!disposedValue)
{
if (disposing)
{
_githubHttpClient.Dispose();
_versionClient.Dispose();
}
disposedValue = true;
}
}
public void Dispose()
{
// Do not change this code. Put cleanup code in 'Dispose(bool disposing)' method
Dispose(disposing: true);
GC.SuppressFinalize(this);
}
}
}