Example #1
0
        public void GetSourceGitClonePR()
        {
            using (TestHostContext tc = new TestHostContext(this))
            {
                var trace = tc.GetTrace();
                // Arrange.
                string dumySourceFolder = Path.Combine(IOUtil.GetBinPath(), "SourceProviderL0");
                var    executionContext = GetTestExecutionContext(tc, dumySourceFolder, "refs/pull/12345", "a596e13f5db8869f44574be0392fb8fe1e790ce4", false);
                var    endpoint         = GetTestSourceEndpoint("https://github.com/Microsoft/vsts-agent", false, false);

                var _gitCommandManager = GetDefaultGitCommandMock();
                tc.SetSingleton <IGitCommandManager>(_gitCommandManager.Object);
                tc.SetSingleton <IWhichUtil>(new WhichUtil());

                GitSourceProvider gitSourceProvider = new GitSourceProvider();
                gitSourceProvider.Initialize(tc);

                // Act.
                gitSourceProvider.GetSourceAsync(executionContext.Object, endpoint, default(CancellationToken)).GetAwaiter().GetResult();

                // Assert.
                _gitCommandManager.Verify(x => x.GitClone(executionContext.Object, dumySourceFolder, It.Is <Uri>(u => u.AbsoluteUri.Equals("https://*****:*****@github.com/Microsoft/vsts-agent")), It.IsAny <string>(), It.IsAny <string>(), It.IsAny <bool>(), It.IsAny <CancellationToken>()));
                _gitCommandManager.Verify(x => x.GitFetch(executionContext.Object, dumySourceFolder, "origin", new List <string>()
                {
                    "+refs/pull/12345:refs/remotes/pull/12345"
                }, It.IsAny <string>(), It.IsAny <string>(), It.IsAny <bool>(), It.IsAny <CancellationToken>()));
                _gitCommandManager.Verify(x => x.GitRemoteSetUrl(executionContext.Object, dumySourceFolder, "origin", "https://github.com/Microsoft/vsts-agent"));
                _gitCommandManager.Verify(x => x.GitRemoteSetPushUrl(executionContext.Object, dumySourceFolder, "origin", "https://github.com/Microsoft/vsts-agent"));
                _gitCommandManager.Verify(x => x.GitCheckout(executionContext.Object, dumySourceFolder, It.Is <string>(s => s.Equals("refs/remotes/pull/12345")), It.IsAny <CancellationToken>()));
            }
        }
        public void GetSourceGitClone()
        {
            using (TestHostContext tc = new TestHostContext(this))
            {
                // Arrange.
                string dumySourceFolder = Path.Combine(IOUtil.GetBinPath(), "SourceProviderL0");
                var    executionContext = GetTestExecutionContext(tc, dumySourceFolder, "master", "a596e13f5db8869f44574be0392fb8fe1e790ce4", false);
                var    endpoint         = GetTestSourceEndpoint("https://github.com/Microsoft/vsts-agent", false, false);

                var _gitCommandManager = GetDefaultGitCommandMock();
                tc.SetSingleton <IGitCommandManager>(_gitCommandManager.Object);
                tc.SetSingleton <IWhichUtil>(new WhichUtil());

                GitSourceProvider gitSourceProvider = new GitSourceProvider();
                gitSourceProvider.Initialize(tc);

                // Act.
                gitSourceProvider.GetSourceAsync(executionContext.Object, endpoint, default(CancellationToken)).GetAwaiter().GetResult();

                // Assert.
                _gitCommandManager.Verify(x => x.GitInit(executionContext.Object, dumySourceFolder));
                _gitCommandManager.Verify(x => x.GitRemoteAdd(executionContext.Object, dumySourceFolder, "origin", "https://github.com/Microsoft/vsts-agent"));
                _gitCommandManager.Verify(x => x.GitRemoteSetUrl(executionContext.Object, dumySourceFolder, "origin", "https://github.com/Microsoft/vsts-agent"));
                _gitCommandManager.Verify(x => x.GitRemoteSetPushUrl(executionContext.Object, dumySourceFolder, "origin", "https://github.com/Microsoft/vsts-agent"));
                _gitCommandManager.Verify(x => x.GitCheckout(executionContext.Object, dumySourceFolder, "a596e13f5db8869f44574be0392fb8fe1e790ce4", It.IsAny <CancellationToken>()));
            }
        }
Example #3
0
        public void GetSourceGitFetchPR()
        {
            using (TestHostContext tc = new TestHostContext(this))
            {
                var trace = tc.GetTrace();
                // Arrange.
                string dumySourceFolder = Path.Combine(IOUtil.GetBinPath(), "SourceProviderL0");
                try
                {
                    Directory.CreateDirectory(dumySourceFolder);
                    string dumyGitFolder = Path.Combine(dumySourceFolder, ".git");
                    Directory.CreateDirectory(dumyGitFolder);
                    string dumyGitConfig = Path.Combine(dumyGitFolder, "config");
                    File.WriteAllText(dumyGitConfig, "test git confg file");

                    var executionContext = GetTestExecutionContext(tc, dumySourceFolder, "refs/pull/12345/merge", "a596e13f5db8869f44574be0392fb8fe1e790ce4", false);
                    var endpoint         = GetTestSourceEndpoint("https://github.com/Microsoft/vsts-agent", false, false);

                    var _gitCommandManager = GetDefaultGitCommandMock();
                    tc.SetSingleton <IGitCommandManager>(_gitCommandManager.Object);
                    tc.SetSingleton <IWhichUtil>(new WhichUtil());

                    GitSourceProvider gitSourceProvider = new GitSourceProvider();
                    gitSourceProvider.Initialize(tc);

                    // Act.
                    gitSourceProvider.GetSourceAsync(executionContext.Object, endpoint, default(CancellationToken)).GetAwaiter().GetResult();

                    // Assert.
                    _gitCommandManager.Verify(x => x.GitDisableAutoGC(executionContext.Object, dumySourceFolder));
                    _gitCommandManager.Verify(x => x.GitRemoteSetUrl(executionContext.Object, dumySourceFolder, "origin", "https://*****:*****@github.com/Microsoft/vsts-agent"));
                    _gitCommandManager.Verify(x => x.GitRemoteSetPushUrl(executionContext.Object, dumySourceFolder, "origin", "https://*****:*****@github.com/Microsoft/vsts-agent"));
                    _gitCommandManager.Verify(x => x.GitFetch(executionContext.Object, dumySourceFolder, "origin", new List <string>()
                    {
                        "+refs/pull/12345/merge:refs/remotes/pull/12345/merge"
                    }, It.IsAny <string>(), It.IsAny <string>(), It.IsAny <bool>(), It.IsAny <CancellationToken>()));
                    _gitCommandManager.Verify(x => x.GitRemoteSetUrl(executionContext.Object, dumySourceFolder, "origin", "https://github.com/Microsoft/vsts-agent"));
                    _gitCommandManager.Verify(x => x.GitRemoteSetPushUrl(executionContext.Object, dumySourceFolder, "origin", "https://github.com/Microsoft/vsts-agent"));
                    _gitCommandManager.Verify(x => x.GitCheckout(executionContext.Object, dumySourceFolder, "refs/remotes/pull/12345/merge", It.IsAny <CancellationToken>()));
                }
                finally
                {
                    IOUtil.DeleteDirectory(dumySourceFolder, CancellationToken.None);
                }
            }
        }
        public void GetSourceReCloneOnUrlNotMatch()
        {
            using (TestHostContext tc = new TestHostContext(this))
            {
                var trace = tc.GetTrace();
                // Arrange.
                string dumySourceFolder = Path.Combine(IOUtil.GetBinPath(), "SourceProviderL0");
                try
                {
                    Directory.CreateDirectory(dumySourceFolder);
                    string dumyGitFolder = Path.Combine(dumySourceFolder, ".git");
                    Directory.CreateDirectory(dumyGitFolder);
                    string dumyGitConfig = Path.Combine(dumyGitFolder, "config");
                    File.WriteAllText(dumyGitConfig, "test git confg file");

                    var executionContext = GetTestExecutionContext(tc, dumySourceFolder, "refs/heads/users/user1", "", true);
                    var endpoint         = GetTestSourceEndpoint("https://github.com/Microsoft/vsts-agent", false, false);

                    var _gitCommandManager = GetDefaultGitCommandMock();
                    _gitCommandManager
                    .Setup(x => x.GitGetFetchUrl(It.IsAny <IExecutionContext>(), It.IsAny <string>()))
                    .Returns(Task.FromResult <Uri>(new Uri("https://github.com/Microsoft/vsts-another-agent")));

                    tc.SetSingleton <IGitCommandManager>(_gitCommandManager.Object);
                    tc.SetSingleton <IWhichUtil>(new WhichUtil());

                    GitSourceProvider gitSourceProvider = new GitSourceProvider();
                    gitSourceProvider.Initialize(tc);

                    // Act.
                    gitSourceProvider.GetSourceAsync(executionContext.Object, endpoint, default(CancellationToken)).GetAwaiter().GetResult();

                    // Assert.
                    _gitCommandManager.Verify(x => x.GitInit(executionContext.Object, dumySourceFolder));
                    _gitCommandManager.Verify(x => x.GitRemoteAdd(executionContext.Object, dumySourceFolder, "origin", "https://github.com/Microsoft/vsts-agent"));
                    _gitCommandManager.Verify(x => x.GitCheckout(executionContext.Object, dumySourceFolder, "refs/remotes/origin/users/user1", It.IsAny <CancellationToken>()));
                }
                finally
                {
                    IOUtil.DeleteDirectory(dumySourceFolder, CancellationToken.None);
                }
            }
        }