コード例 #1
0
        public async Task FallbackForkIsNotUsedWhenItIsNotPushable()
        {
            var fallbackFork     = DefaultFork();
            var fallbackRepoData = RepositoryBuilder.MakeRepository(true, false);

            var collaborationPlatform = Substitute.For <ICollaborationPlatform>();

            collaborationPlatform.GetUserRepository(fallbackFork.Owner, fallbackFork.Name)
            .Returns(fallbackRepoData);

            var forkFinder = new GitHubForkFinder(collaborationPlatform, Substitute.For <INuKeeperLogger>(), ForkMode.PreferFork);

            var fork = await forkFinder.FindPushFork("testUser", fallbackFork);

            Assert.That(fork, Is.Null);
        }
コード例 #2
0
        public async Task WhenUnsuitableUserForkIsFoundItIsNotUsed()
        {
            var fallbackFork = NoMatchFork();

            var userRepo = RepositoryBuilder.MakeRepository();

            var collaborationPlatform = Substitute.For <ICollaborationPlatform>();

            collaborationPlatform.GetUserRepository(Arg.Any <string>(), Arg.Any <string>())
            .Returns(userRepo);

            var forkFinder = new GitHubForkFinder(collaborationPlatform, Substitute.For <INuKeeperLogger>(), ForkMode.PreferFork);

            var fork = await forkFinder.FindPushFork("testUser", fallbackFork);

            Assert.That(fork, Is.EqualTo(fallbackFork));
        }
コード例 #3
0
        public async Task SingleRepoOnlyModeWillNotPreferFork()
        {
            var fallbackFork = DefaultFork();

            var userRepo = RepositoryBuilder.MakeRepository();

            var collaborationPlatform = Substitute.For <ICollaborationPlatform>();

            collaborationPlatform.GetUserRepository(Arg.Any <string>(), Arg.Any <string>())
            .Returns(userRepo);

            var forkFinder = new GitHubForkFinder(collaborationPlatform, Substitute.For <INuKeeperLogger>(), ForkMode.SingleRepositoryOnly);

            var fork = await forkFinder.FindPushFork("testUser", fallbackFork);

            Assert.That(fork, Is.EqualTo(fallbackFork));
        }
コード例 #4
0
        public async Task WhenSuitableUserForkIsFound_ThatMatchesCloneHtmlUrl_ItIsUsedOverFallback()
        {
            var fallbackFork = new ForkData(new Uri(RepositoryBuilder.ParentCloneUrl), "testOrg", "someRepo");

            var userRepo = RepositoryBuilder.MakeRepository();

            var collaborationPlatform = Substitute.For <ICollaborationPlatform>();

            collaborationPlatform.GetUserRepository(Arg.Any <string>(), Arg.Any <string>())
            .Returns(userRepo);

            var forkFinder = new GitHubForkFinder(collaborationPlatform, Substitute.For <INuKeeperLogger>(), ForkMode.PreferFork);

            var fork = await forkFinder.FindPushFork("testUser", fallbackFork);

            Assert.That(fork, Is.Not.EqualTo(fallbackFork));
            AssertForkMatchesRepo(fork, userRepo);
        }
コード例 #5
0
        public async Task OrgModeWhenThereAreIncludesAndExcludes_OnlyConsiderMatchesButRemoveNonMatching()
        {
            var inputRepos = new List <Repository>
            {
                RepositoryBuilder.MakeRepository(name: "foo"),
                RepositoryBuilder.MakeRepository(name: "bar")
            };

            var githubRepositoryDiscovery = MakeGithubRepositoryDiscovery(inputRepos.AsReadOnly());

            var settings = OrgModeSettings();

            settings.IncludeRepos = new Regex("^bar");
            settings.ExcludeRepos = new Regex("^bar");
            var repos = await githubRepositoryDiscovery.GetRepositories(settings);

            Assert.That(repos, Is.Not.Null);
            Assert.That(repos.Count(), Is.EqualTo(0));
        }
コード例 #6
0
        public async Task OrgModeValidReposAreIncluded()
        {
            var inputRepos = new List <Repository>
            {
                RepositoryBuilder.MakeRepository()
            };

            var githubRepositoryDiscovery = MakeGithubRepositoryDiscovery(inputRepos.AsReadOnly());

            var repos = await githubRepositoryDiscovery.GetRepositories(OrgModeSettings());

            Assert.That(repos, Is.Not.Null);
            Assert.That(repos, Is.Not.Empty);
            Assert.That(repos.Count(), Is.EqualTo(1));

            var firstRepo = repos.First();

            Assert.That(firstRepo.RepositoryName, Is.EqualTo(inputRepos[0].Name));
            Assert.That(firstRepo.RepositoryUri.ToString(), Is.EqualTo(inputRepos[0].HtmlUrl));
        }
コード例 #7
0
        public async Task OrgModeInvalidReposAreExcluded()
        {
            var inputRepos = new List <Repository>
            {
                RepositoryBuilder.MakeRepository("http://a.com/repo1", "http://a.com/repo1.git", false),
                RepositoryBuilder.MakeRepository("http://b.com/repob", "http://b.com/repob.git", true)
            };

            var githubRepositoryDiscovery = MakeGithubRepositoryDiscovery(inputRepos.AsReadOnly());

            var repos = await githubRepositoryDiscovery.GetRepositories(OrgModeSettings());

            Assert.That(repos, Is.Not.Null);
            Assert.That(repos, Is.Not.Empty);
            Assert.That(repos.Count(), Is.EqualTo(1));

            var firstRepo = repos.First();

            Assert.That(firstRepo.RepositoryName, Is.EqualTo(inputRepos[1].Name));
            Assert.That(firstRepo.RepositoryUri.ToString(), Is.EqualTo(inputRepos[1].HtmlUrl));
        }
コード例 #8
0
        public async Task SingleRepoOnlyModeWillNotUseForkWhenUpstreamIsUnsuitable()
        {
            var fallbackFork = DefaultFork();

            var collaborationPlatform = Substitute.For <ICollaborationPlatform>();

            var defaultRepo = RepositoryBuilder.MakeRepository(true, false);

            collaborationPlatform.GetUserRepository(fallbackFork.Owner, fallbackFork.Name)
            .Returns(defaultRepo);

            var userRepo = RepositoryBuilder.MakeRepository();

            collaborationPlatform.GetUserRepository("testUser", fallbackFork.Name)
            .Returns(userRepo);

            var forkFinder = new GitHubForkFinder(collaborationPlatform, Substitute.For <INuKeeperLogger>(), ForkMode.SingleRepositoryOnly);

            var fork = await forkFinder.FindPushFork("testUser", fallbackFork);

            Assert.That(fork, Is.Null);
        }
コード例 #9
0
        public async Task WhenUserForkIsNotFoundItIsCreated()
        {
            var fallbackFork = DefaultFork();

            var userRepo = RepositoryBuilder.MakeRepository();

            var collaborationPlatform = Substitute.For <ICollaborationPlatform>();

            collaborationPlatform.GetUserRepository(Arg.Any <string>(), Arg.Any <string>())
            .Returns((Repository)null);
            collaborationPlatform.MakeUserFork(Arg.Any <string>(), Arg.Any <string>())
            .Returns(userRepo);

            var forkFinder = new GitHubForkFinder(collaborationPlatform, Substitute.For <INuKeeperLogger>(), ForkMode.PreferFork);

            var actualFork = await forkFinder.FindPushFork("testUser", fallbackFork);

            await collaborationPlatform.Received(1).MakeUserFork(Arg.Any <string>(), Arg.Any <string>());

            Assert.That(actualFork, Is.Not.Null);
            Assert.That(actualFork, Is.Not.EqualTo(fallbackFork));
        }
コード例 #10
0
        public async Task RepoModeIgnoresIncludesAndExcludes()
        {
            var settings = new SourceControlServerSettings
            {
                Repository   = new RepositorySettings(RepositoryBuilder.MakeRepository(name: "foo")),
                Scope        = ServerScope.Repository,
                IncludeRepos = new Regex("^foo"),
                ExcludeRepos = new Regex("^foo")
            };

            var githubRepositoryDiscovery = MakeGithubRepositoryDiscovery();

            var reposResponse = await githubRepositoryDiscovery.GetRepositories(settings);

            var repos = reposResponse.ToList();

            Assert.That(repos, Is.Not.Null);
            Assert.That(repos.Count, Is.EqualTo(1));

            var firstRepo = repos.First();

            Assert.That(firstRepo.RepositoryName, Is.EqualTo("foo"));
        }