/
ScalarCloneFromGithub.cs
74 lines (58 loc) · 3.1 KB
/
ScalarCloneFromGithub.cs
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
using NUnit.Framework;
using Scalar.FunctionalTests.FileSystemRunners;
using Scalar.FunctionalTests.Tools;
using Scalar.Tests.Should;
using System;
using System.IO;
using System.Linq;
namespace Scalar.FunctionalTests.Tests.MultiEnlistmentTests
{
[Category(Categories.GitRepository)]
public class ScalarCloneFromGithub : TestsWithMultiEnlistment
{
private static readonly string MicrosoftScalarHttp = "https://github.com/microsoft/scalar";
private FileSystemRunner fileSystem;
public ScalarCloneFromGithub()
{
this.fileSystem = new SystemIORunner();
}
[TestCase]
public void PartialCloneHttps()
{
ScalarFunctionalTestEnlistment enlistment = this.CreateNewEnlistment(
url: MicrosoftScalarHttp,
branch: "for-tests",
fullClone: false);
VerifyPartialCloneBehavior(enlistment);
}
private void VerifyPartialCloneBehavior(ScalarFunctionalTestEnlistment enlistment)
{
this.fileSystem.DirectoryExists(enlistment.RepoRoot).ShouldBeTrue($"'{enlistment.RepoRoot}' does not exist");
string gitPack = Path.Combine(enlistment.RepoRoot, ".git", "objects", "pack");
this.fileSystem.DirectoryExists(gitPack).ShouldBeTrue($"'{gitPack}' does not exist");
void checkPacks(string dir, int count, string when)
{
string dirContents = this.fileSystem
.EnumerateDirectory(dir);
dirContents
.Split()
.Where(file => string.Equals(Path.GetExtension(file), ".pack", FileSystemHelpers.PathComparison))
.Count()
.ShouldEqual(count, $"'{dir}' after '{when}': '{dirContents}'");
}
// Two packs for clone: commits and trees, blobs at root
checkPacks(gitPack, 2, "clone");
string srcScalar = Path.Combine(enlistment.RepoRoot, "Scalar");
this.fileSystem.DirectoryExists(srcScalar).ShouldBeFalse($"'{srcScalar}' should not exist due to sparse-checkout");
ProcessResult sparseCheckoutResult = GitProcess.InvokeProcess(enlistment.RepoRoot, "sparse-checkout disable");
sparseCheckoutResult.ExitCode.ShouldEqual(0, "git sparse-checkout disable exit code");
this.fileSystem.DirectoryExists(srcScalar).ShouldBeTrue($"'{srcScalar}' should exist after sparse-checkout");
// Three packs for sparse-chekcout: commits and trees, blobs at root, blobs outside root
checkPacks(gitPack, 3, "sparse-checkout");
ProcessResult checkoutResult = GitProcess.InvokeProcess(enlistment.RepoRoot, "checkout HEAD~10");
checkoutResult.ExitCode.ShouldEqual(0, "git checkout exit code");
// Four packs for chekcout: commits and trees, blobs at root, blobs outside root, checkout diff
checkPacks(gitPack, 4, "checkout");
}
}
}