-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor and stabilize Send/Receive tests (#715)
* Refactor Send/Receive tests * move `InitLocalFlexProjectWithRepo` into SR Fixture because it only works when the fixture is used * Refactor SendReceiveAfterProjectReset and other things * Fix mistakes --------- Co-authored-by: Kevin Hahn <hahn.kev@gmail.com>
- Loading branch information
Showing
14 changed files
with
393 additions
and
295 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 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 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,63 @@ | ||
using System.IO.Compression; | ||
using System.Runtime.CompilerServices; | ||
using Chorus.VcsDrivers.Mercurial; | ||
using LexCore.Utils; | ||
using Shouldly; | ||
using SIL.Progress; | ||
using Testing.ApiTests; | ||
using Testing.Services; | ||
using static Testing.Services.Constants; | ||
|
||
namespace Testing.Fixtures; | ||
|
||
public class SendReceiveFixture : IAsyncLifetime | ||
{ | ||
private readonly DirectoryInfo _templateRepo = new(Path.Join(BasePath, "_template-repo_")); | ||
public ApiTestBase AdminApiTester { get; } = new(); | ||
|
||
public async Task InitializeAsync() | ||
{ | ||
DeletePreviousTestFiles(); | ||
await DownloadTemplateRepo(); | ||
await AdminApiTester.LoginAs(AdminAuth.Username, AdminAuth.Password); | ||
} | ||
|
||
public Task DisposeAsync() | ||
{ | ||
return Task.CompletedTask; | ||
} | ||
|
||
private static void DeletePreviousTestFiles() | ||
{ | ||
if (Directory.Exists(BasePath)) Directory.Delete(BasePath, true); | ||
} | ||
|
||
private async Task DownloadTemplateRepo() | ||
{ | ||
await using var stream = await AdminApiTester.HttpClient.GetStreamAsync("https://drive.google.com/uc?export=download&id=1w357T1Ti7bDwEof4HPBUZ5gB7WSKA5O2"); | ||
using var zip = new ZipArchive(stream); | ||
zip.ExtractToDirectory(_templateRepo.FullName); | ||
} | ||
|
||
public ProjectConfig InitLocalFlexProjectWithRepo(HgProtocol? protocol = null, [CallerMemberName] string projectName = "") | ||
{ | ||
var projectConfig = Utils.GetNewProjectConfig(protocol, projectName); | ||
InitLocalFlexProjectWithRepo(projectConfig); | ||
return projectConfig; | ||
} | ||
|
||
public void InitLocalFlexProjectWithRepo(ProjectPath projectPath) | ||
{ | ||
var projectDir = Directory.CreateDirectory(projectPath.Dir); | ||
FileUtils.CopyFilesRecursively(_templateRepo, projectDir); | ||
File.Move(Path.Join(projectPath.Dir, "kevin-test-01.fwdata"), projectPath.FwDataFile); | ||
Directory.EnumerateFiles(projectPath.Dir).ShouldContain(projectPath.FwDataFile); | ||
|
||
// hack around the fact that our send and receive won't create a repo from scratch. | ||
var progress = new NullProgress(); | ||
HgRunner.Run("hg init", projectPath.Dir, 1, progress); | ||
HgRunner.Run("hg branch 7500002.7000072", projectPath.Dir, 1, progress); | ||
HgRunner.Run($"hg add Lexicon.fwstub", projectPath.Dir, 1, progress); | ||
HgRunner.Run("""hg commit -m "first commit" """, projectPath.Dir, 1, progress); | ||
} | ||
} |
This file contains 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,11 @@ | ||
namespace Testing.Services; | ||
|
||
public static class Constants | ||
{ | ||
public static readonly string BasePath = Path.Join(Path.GetTempPath(), "SR_Tests"); | ||
public static readonly SendReceiveAuth ManagerAuth = new("manager", TestingEnvironmentVariables.DefaultPassword); | ||
public static readonly SendReceiveAuth AdminAuth = new("admin", TestingEnvironmentVariables.DefaultPassword); | ||
public static readonly SendReceiveAuth InvalidPass = new("manager", "incorrect_pass"); | ||
public static readonly SendReceiveAuth InvalidUser = new("invalid_user", TestingEnvironmentVariables.DefaultPassword); | ||
public static readonly SendReceiveAuth UnauthorizedUser = new("user", TestingEnvironmentVariables.DefaultPassword); | ||
} |
This file contains 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 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.