public void CanGetCacheServerWithNoConfig()
        {
            MockScalarEnlistment enlistment = this.CreateEnlistment();

            this.ValidateIsNone(enlistment, CacheServerResolver.GetCacheServerFromConfig(enlistment));
            CacheServerResolver.GetUrlFromConfig(enlistment).ShouldEqual(enlistment.RepoUrl);
        }
예제 #2
0
        public void CanGetLocalCacheKeyFromURL()
        {
            MockScalarEnlistment enlistment         = CreateEnlistment("mock://repoUrl");
            LocalCacheResolver   localCacheResolver = new LocalCacheResolver(enlistment);

            LocalKeyShouldBeResolvedFromURL(localCacheResolver, vstsInfo: null);
        }
예제 #3
0
        public void CanGetLocalCacheKeyFromRepoInfo()
        {
            List <string> repoIds = new List <string>
            {
                "df3216c6-6d33-476e-8d89-e877a6d74c79",
                "testId",
                "826847f5da3ef78114b2a9d5253ada9d95265c76"
            };

            MockTracer           tracer             = new MockTracer();
            MockScalarEnlistment enlistment         = CreateEnlistment("mock://repoUrl");
            LocalCacheResolver   localCacheResolver = new LocalCacheResolver(enlistment);

            foreach (string repoId in repoIds)
            {
                VstsInfoData vstsInfo = new VstsInfoData();
                vstsInfo.Repository    = new VstsInfoData.RepositoryDetails();
                vstsInfo.Repository.Id = repoId;

                localCacheResolver.TryGetLocalCacheKeyFromRepoInfoOrURL(
                    tracer,
                    vstsInfo,
                    out string localCacheKey,
                    out string errorMessage).ShouldBeTrue();
                errorMessage.ShouldBeEmpty();
                localCacheKey.ShouldEqual($"{RepoIdKeyPrefix}{repoId}");
            }
        }
        public void CanGetCacheServerFromNewConfig()
        {
            MockScalarEnlistment enlistment  = this.CreateEnlistment(CacheServerUrl);
            CacheServerInfo      cacheServer = CacheServerResolver.GetCacheServerFromConfig(enlistment);

            cacheServer.Url.ShouldEqual(CacheServerUrl);
            CacheServerResolver.GetUrlFromConfig(enlistment).ShouldEqual(CacheServerUrl);
        }
예제 #5
0
        private void TestSetup()
        {
            ITracer            tracer     = new MockTracer();
            ScalarEnlistment   enlistment = new MockScalarEnlistment();
            PhysicalFileSystem fileSystem = new MockFileSystem(new MockDirectory(enlistment.EnlistmentRoot, null, null));

            this.context = new ScalarContext(tracer, fileSystem, enlistment);
        }
예제 #6
0
        private void TestSetup()
        {
            this.gitProcess = new MockGitProcess();

            // Create enlistment using git process
            ScalarEnlistment enlistment = new MockScalarEnlistment(this.gitProcess);

            PhysicalFileSystem fileSystem = new MockFileSystem(new MockDirectory(enlistment.EnlistmentRoot, null, null));

            // Create and return Context
            this.tracer  = new MockTracer();
            this.context = new ScalarContext(this.tracer, fileSystem, enlistment: enlistment);
        }
        public void CanResolveUrlAsRepoUrl()
        {
            MockScalarEnlistment enlistment = this.CreateEnlistment();
            CacheServerResolver  resolver   = this.CreateResolver(enlistment);

            this.ValidateIsNone(enlistment, resolver.ResolveNameFromRemote(enlistment.RepoUrl, this.CreateScalarConfig()));
            this.ValidateIsNone(enlistment, resolver.ResolveNameFromRemote(enlistment.RepoUrl + "/", this.CreateScalarConfig()));
            this.ValidateIsNone(enlistment, resolver.ResolveNameFromRemote(enlistment.RepoUrl + "//", this.CreateScalarConfig()));
            this.ValidateIsNone(enlistment, resolver.ResolveNameFromRemote(enlistment.RepoUrl.ToUpper(), this.CreateScalarConfig()));
            this.ValidateIsNone(enlistment, resolver.ResolveNameFromRemote(enlistment.RepoUrl.ToUpper() + "/", this.CreateScalarConfig()));
            this.ValidateIsNone(enlistment, resolver.ResolveNameFromRemote(enlistment.RepoUrl.ToLower(), this.CreateScalarConfig()));
            this.ValidateIsNone(enlistment, resolver.ResolveNameFromRemote(enlistment.RepoUrl.ToLower() + "/", this.CreateScalarConfig()));
        }
        public void CanParseAndResolveDefaultWhenServerAdvertisesNullListOfCacheServers()
        {
            MockScalarEnlistment enlistment = this.CreateEnlistment();
            CacheServerResolver  resolver   = this.CreateResolver(enlistment);

            CacheServerInfo resolvedCacheServer;
            string          error;

            resolver.TryResolveUrlFromRemote(CacheServerInfo.ReservedNames.Default, this.CreateDefaultDeserializedScalarConfig(), out resolvedCacheServer, out error)
            .ShouldEqual(true);

            this.ValidateIsNone(enlistment, resolvedCacheServer);
        }
        public void CanParseAndResolveOtherWhenServerAdvertisesNullListOfCacheServers()
        {
            MockScalarEnlistment enlistment = this.CreateEnlistment();
            CacheServerResolver  resolver   = this.CreateResolver(enlistment);

            CacheServerInfo resolvedCacheServer;
            string          error;

            resolver.TryResolveUrlFromRemote(CacheServerInfo.ReservedNames.None, this.CreateDefaultDeserializedScalarConfig(), out resolvedCacheServer, out error)
            .ShouldEqual(false, "Should not succeed in resolving the name 'None'");

            resolvedCacheServer.ShouldEqual(null);
            error.ShouldNotBeNull();
        }
예제 #10
0
        public void FallBackToUsingURLWhenRepoInfoEmpty()
        {
            MockScalarEnlistment enlistment         = CreateEnlistment("mock://repoUrl");
            LocalCacheResolver   localCacheResolver = new LocalCacheResolver(enlistment);

            VstsInfoData vstsInfo = new VstsInfoData();

            LocalKeyShouldBeResolvedFromURL(localCacheResolver, vstsInfo);

            vstsInfo.Repository = new VstsInfoData.RepositoryDetails();
            LocalKeyShouldBeResolvedFromURL(localCacheResolver, vstsInfo);

            vstsInfo.Repository.Id = string.Empty;
            LocalKeyShouldBeResolvedFromURL(localCacheResolver, vstsInfo);

            vstsInfo.Repository.Id = "   ";
            LocalKeyShouldBeResolvedFromURL(localCacheResolver, vstsInfo);
        }
        public void CanParseAndResolveNoCacheServer()
        {
            MockScalarEnlistment enlistment = this.CreateEnlistment();
            CacheServerResolver  resolver   = this.CreateResolver(enlistment);

            this.ValidateIsNone(enlistment, resolver.ParseUrlOrFriendlyName(CacheServerInfo.ReservedNames.None));
            this.ValidateIsNone(enlistment, resolver.ParseUrlOrFriendlyName(enlistment.RepoUrl));
            this.ValidateIsNone(enlistment, resolver.ParseUrlOrFriendlyName(enlistment.RepoUrl));
            this.ValidateIsNone(enlistment, resolver.ParseUrlOrFriendlyName(enlistment.RepoUrl + "/"));
            this.ValidateIsNone(enlistment, resolver.ParseUrlOrFriendlyName(enlistment.RepoUrl + "//"));
            this.ValidateIsNone(enlistment, resolver.ParseUrlOrFriendlyName(enlistment.RepoUrl.ToUpper()));
            this.ValidateIsNone(enlistment, resolver.ParseUrlOrFriendlyName(enlistment.RepoUrl.ToUpper() + "/"));
            this.ValidateIsNone(enlistment, resolver.ParseUrlOrFriendlyName(enlistment.RepoUrl.ToLower()));
            this.ValidateIsNone(enlistment, resolver.ParseUrlOrFriendlyName(enlistment.RepoUrl.ToLower() + "/"));

            CacheServerInfo resolvedCacheServer;
            string          error;

            resolver.TryResolveUrlFromRemote(CacheServerInfo.ReservedNames.None, this.CreateScalarConfig(), out resolvedCacheServer, out error)
            .ShouldEqual(false, "Should not succeed in resolving the name 'None'");

            resolvedCacheServer.ShouldEqual(null);
            error.ShouldNotBeNull();
        }
예제 #12
0
        private void TestSetup(DateTime lastRun)
        {
            string lastRunTime = EpochConverter.ToUnixEpochSeconds(lastRun).ToString();

            // Create GitProcess
            this.gitProcess = new MockGitProcess();
            this.gitProcess.SetExpectedCommandResult(
                PrunePackedCommand,
                () => new GitProcess.Result(string.Empty, string.Empty, GitProcess.Result.SuccessCode));

            // Create enlistment using git process
            ScalarEnlistment enlistment = new MockScalarEnlistment(this.gitProcess);

            string packPrefix = Path.Combine(enlistment.GitPackRoot, "from-loose");

            this.packCommand = $"pack-objects {packPrefix} --non-empty --window=0 --depth=0 -q";

            this.gitProcess.SetExpectedCommandResult(
                this.packCommand,
                () => new GitProcess.Result(string.Empty, string.Empty, GitProcess.Result.SuccessCode));

            // Create a last run time file
            MockFile timeFile = new MockFile(Path.Combine(enlistment.GitObjectsRoot, "info", LooseObjectsStep.LooseObjectsLastRunFileName), lastRunTime);

            // Create info directory to hold last run time file
            MockDirectory infoRoot = new MockDirectory(Path.Combine(enlistment.GitObjectsRoot, "info"), null, new List <MockFile>()
            {
                timeFile
            });

            // Create Hex Folder 1 with 1 File
            MockDirectory hex1 = new MockDirectory(
                Path.Combine(enlistment.GitObjectsRoot, "AA"),
                null,
                new List <MockFile>()
            {
                new MockFile(Path.Combine(enlistment.GitObjectsRoot, "AA", "1156f4f2b850673090c285289ea8475d629fe1"), "one")
            });

            // Create Hex Folder 2 with 2 Files
            MockDirectory hex2 = new MockDirectory(
                Path.Combine(enlistment.GitObjectsRoot, "F1"),
                null,
                new List <MockFile>()
            {
                new MockFile(Path.Combine(enlistment.GitObjectsRoot, "F1", "1156f4f2b850673090c285289ea8475d629fe2"), "two"),
                new MockFile(Path.Combine(enlistment.GitObjectsRoot, "F1", "1156f4f2b850673090c285289ea8475d629fe3"), "three")
            });

            // Create NonHex Folder with 4 Files
            MockDirectory nonhex = new MockDirectory(
                Path.Combine(enlistment.GitObjectsRoot, "ZZ"),
                null,
                new List <MockFile>()
            {
                new MockFile(Path.Combine(enlistment.GitObjectsRoot, "ZZ", "1156f4f2b850673090c285289ea8475d629fe4"), "4"),
                new MockFile(Path.Combine(enlistment.GitObjectsRoot, "ZZ", "1156f4f2b850673090c285289ea8475d629fe5"), "5"),
                new MockFile(Path.Combine(enlistment.GitObjectsRoot, "ZZ", "1156f4f2b850673090c285289ea8475d629fe6"), "6"),
                new MockFile(Path.Combine(enlistment.GitObjectsRoot, "ZZ", "1156f4f2b850673090c285289ea8475d629fe7"), "7")
            });

            MockDirectory pack = new MockDirectory(
                enlistment.GitPackRoot,
                null,
                new List <MockFile>());

            // Create git objects directory
            MockDirectory gitObjectsRoot = new MockDirectory(enlistment.GitObjectsRoot, new List <MockDirectory>()
            {
                infoRoot, hex1, hex2, nonhex, pack
            }, null);

            // Add object directory to file System
            List <MockDirectory> directories = new List <MockDirectory>()
            {
                gitObjectsRoot
            };
            PhysicalFileSystem fileSystem = new MockFileSystem(new MockDirectory(enlistment.EnlistmentRoot, directories, null));

            // Create and return Context
            this.tracer  = new MockTracer();
            this.context = new ScalarContext(this.tracer, fileSystem, enlistment: enlistment);
        }
예제 #13
0
        private void TestSetup(DateTime lastRun, bool failOnVerify = false)
        {
            string lastRunTime = EpochConverter.ToUnixEpochSeconds(lastRun).ToString();

            this.gitProcess = new MockGitProcess();

            // Create enlistment using git process
            ScalarEnlistment enlistment = new MockScalarEnlistment(this.gitProcess);

            // Create a last run time file
            MockFile timeFile = new MockFile(Path.Combine(enlistment.GitObjectsRoot, "info", PackfileMaintenanceStep.PackfileLastRunFileName), lastRunTime);

            // Create info directory to hold last run time file
            MockDirectory info = new MockDirectory(
                Path.Combine(enlistment.GitObjectsRoot, "info"),
                null,
                new List <MockFile>()
            {
                timeFile
            });

            // Create pack info
            MockDirectory pack = new MockDirectory(
                enlistment.GitPackRoot,
                null,
                new List <MockFile>()
            {
                new MockFile(Path.Combine(enlistment.GitPackRoot, "pack-1.pack"), "one"),
                new MockFile(Path.Combine(enlistment.GitPackRoot, "pack-1.idx"), "1"),
                new MockFile(Path.Combine(enlistment.GitPackRoot, "pack-2.pack"), "two"),
                new MockFile(Path.Combine(enlistment.GitPackRoot, "pack-2.idx"), "2"),
                new MockFile(Path.Combine(enlistment.GitPackRoot, "pack-3.pack"), "three"),
                new MockFile(Path.Combine(enlistment.GitPackRoot, "pack-3.idx"), "3"),
                new MockFile(Path.Combine(enlistment.GitPackRoot, KeepName), string.Empty),
                new MockFile(Path.Combine(enlistment.GitPackRoot, StaleIdxName), "4"),
            });

            // Create git objects directory
            MockDirectory gitObjectsRoot = new MockDirectory(enlistment.GitObjectsRoot, new List <MockDirectory>()
            {
                info, pack
            }, null);

            // Add object directory to file System
            List <MockDirectory> directories = new List <MockDirectory>()
            {
                gitObjectsRoot
            };
            PhysicalFileSystem fileSystem = new MockFileSystem(new MockDirectory(enlistment.EnlistmentRoot, directories, null));

            // Create and return Context
            this.tracer  = new MockTracer();
            this.context = new ScalarContext(this.tracer, fileSystem, enlistment);

            this.gitProcess.SetExpectedCommandResult(
                this.WriteCommand,
                () => new GitProcess.Result(string.Empty, string.Empty, GitProcess.Result.SuccessCode));
            this.gitProcess.SetExpectedCommandResult(
                this.ExpireCommand,
                () => new GitProcess.Result(string.Empty, string.Empty, GitProcess.Result.SuccessCode));
            this.gitProcess.SetExpectedCommandResult(
                this.VerifyCommand,
                () => new GitProcess.Result(string.Empty, string.Empty, failOnVerify ? GitProcess.Result.GenericFailureCode : GitProcess.Result.SuccessCode));
            this.gitProcess.SetExpectedCommandResult(
                this.RepackCommand,
                () => new GitProcess.Result(string.Empty, string.Empty, GitProcess.Result.SuccessCode));
        }
 private CacheServerResolver CreateResolver(MockScalarEnlistment enlistment = null)
 {
     enlistment = enlistment ?? this.CreateEnlistment();
     return(new CacheServerResolver(new MockTracer(), enlistment));
 }