-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathUnityVersionControlFileHashProviderTest.cs
More file actions
59 lines (50 loc) · 2.76 KB
/
UnityVersionControlFileHashProviderTest.cs
File metadata and controls
59 lines (50 loc) · 2.76 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
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
using System.Collections.Generic;
using System.IO;
using System.Threading;
using System.Threading.Tasks;
using BuildXL.Utilities;
using Microsoft.MSBuildCache.SourceControl.UnityVersionControl;
using Microsoft.MSBuildCache.Tests.Mocks;
using Microsoft.VisualStudio.TestTools.UnitTesting;
namespace Microsoft.MSBuildCache.Tests.SourceControl;
[TestClass]
public class UnityVersionControlFileHashProviderTests
{
private static readonly byte[] FakeHash = { 0, 1, 2, 3, 4 };
#pragma warning disable CS8618 // Non-nullable field must contain a non-null value when exiting constructor. Consider declaring as nullable. Justification: Always set by MSTest
public TestContext TestContext { get; set; }
#pragma warning restore CS8618 // Non-nullable field must contain a non-null value when exiting constructor. Consider declaring as nullable.
private static Task FakeHasher(List<string> filesToRehash, Dictionary<string, byte[]> fileHashes)
{
foreach (string file in filesToRehash)
{
fileHashes[file] = FakeHash;
}
return Task.CompletedTask;
}
[TestMethod, Timeout(10000)]
public async Task ParseCmLsFiles()
{
const string repoRoot = @"C:\work\MSBuildCacheTest";
// This has two modified and one untracked files
const string lsFilesOutput = "c:\\work\\MSBuildCacheTest\tFZMuOF2WDemh7irROkxyWw==\nc:\\work\\MSBuildCacheTest\\foo.txt\t9nwry/z6MPzLNvctyiKoFw==\nc:\\work\\MSBuildCacheTest\\bar.txt\t";
UnityVersionControlFileHashProvider unityFileHashProvider = new(NullPluginLogger.Instance);
Dictionary<string, byte[]> hashes = await unityFileHashProvider.ParseUnityLsFiles(new StringReader(lsFilesOutput), FakeHasher);
int filesExpected = 3;
Assert.AreEqual(filesExpected, hashes.Count, $"should be {filesExpected} files in this output");
string barPath = Path.Combine(repoRoot, @"bar.txt").ToUpperInvariant();
Assert.AreEqual(FakeHash, hashes[barPath], $"bytes of {barPath} should be {FakeHash} since it should have gotten hashed by the FakeHasher");
Assert.AreEqual("0001020304", hashes[Path.Combine(repoRoot, "bar.txt")].ToHex());
}
[TestMethod, Timeout(10000)]
public async Task ParseRealCmLsFiles()
{
const string repoRoot = @"C:\work\devroot";
UnityVersionControlFileHashProvider unityFileHashProvider = new(NullPluginLogger.Instance);
var dict = await unityFileHashProvider.GetFileHashesAsync(repoRoot, CancellationToken.None);
int filesExpected = 116921;
Assert.AreEqual(filesExpected, dict.Count, $"should be {filesExpected} files in this output");
}
}