Пример #1
0
        public async Task IsValid_ReturnsOkIfThereIsNoJenkinsFile()
        {
            var repository = CreateRepository("repomen");

            MockRepositoryContentClient.GetAllContentsByRef(Owner.Name, repository.Name, MainBranch).Returns(Task.FromResult((IReadOnlyList <RepositoryContent>) new List <RepositoryContent>()));

            var result = await _rule.IsValid(MockClient, repository);

            Assert.IsTrue(result.IsValid);
        }
Пример #2
0
        public async Task IsValid_ReturnsFalseIfNoCodeownersFile()
        {
            var repository = CreateRepository("repo");

            MockRepositoryContentClient.GetAllContentsByRef(Owner.Name, repository.Name, MainBranch)
            .Returns(Task.FromResult((IReadOnlyList <RepositoryContent>) new List <RepositoryContent>()));

            var result = await _rule.IsValid(MockClient, repository);

            StringAssert.AreEqualIgnoringCase(result.HowToFix, "Add CODEOWNERS file.");
            Assert.IsFalse(result.IsValid);
        }
Пример #3
0
        public async Task IsValid_ReturnsFalseWhenReadmeExistsWithoutContent()
        {
            var readme = CreateContent("README.md", "");
            IReadOnlyList <RepositoryContent> contents = new[] { readme };
            var repository = CreateRepository("repomen");

            MockRepositoryContentClient.GetAllContentsByRef(Owner.Name, repository.Name, contents[0].Name, MainBranch).Returns(Task.FromResult(contents));
            MockRepositoryContentClient.GetAllContentsByRef(Owner.Name, repository.Name, MainBranch).Returns(Task.FromResult(contents));

            var result = await _rule.IsValid(MockClient, repository);

            Assert.IsFalse(result.IsValid);
        }
Пример #4
0
        public async Task IsValid_ReturnsOkWhenReadmeExists([Values("ReAdMe.md", "rEaDmE.txt", "README", "readme", "ReAdMe.doc")] string readMeName)
        {
            var readme = CreateContent(readMeName, "random content");
            IReadOnlyList <RepositoryContent> contents = new[] { readme };
            var repository = CreateRepository("repomen");

            MockRepositoryContentClient.GetAllContentsByRef(Owner.Name, repository.Name, contents[0].Name, MainBranch).Returns(Task.FromResult(contents));
            MockRepositoryContentClient.GetAllContentsByRef(Owner.Name, repository.Name, MainBranch).Returns(Task.FromResult(contents));

            var result = await _rule.IsValid(MockClient, repository);

            Assert.IsTrue(result.IsValid);
        }
Пример #5
0
        public async Task IsValid_ReturnsTrueWhenPtcsLibraryIsNewest()
        {
            var content = CreateContent("JENKINSFILE", $"library 'jenkins-ptcs-library@{ExpectedJenkinsPtcsLibrary}'");
            IReadOnlyList <RepositoryContent> contents = new[] { content };

            var repository = CreateRepository("repomen");

            MockRepositoryContentClient.GetAllContentsByRef(Owner.Name, repository.Name, MainBranch).Returns(Task.FromResult(contents));
            MockRepositoryContentClient.GetAllContentsByRef(Owner.Name, repository.Name, contents[0].Name, MainBranch).Returns(Task.FromResult(contents));

            var result = await _rule.IsValid(MockClient, repository);

            Assert.IsTrue(result.IsValid);
        }
Пример #6
0
        public async Task IsValid_ReturnsFalseWhenPtcsLibraryIsOldWithDoubleQuotest()
        {
            var content = CreateContent("JENKINSFILE", "library \"[email protected]\"");
            IReadOnlyList <RepositoryContent> contents = new[] { content };

            var repository = CreateRepository("repomen");

            MockRepositoryContentClient.GetAllContentsByRef(Owner.Name, repository.Name, MainBranch).Returns(Task.FromResult(contents));
            MockRepositoryContentClient.GetAllContentsByRef(Owner.Name, repository.Name, contents[0].Name, MainBranch).Returns(Task.FromResult(contents));

            var result = await _rule.IsValid(MockClient, repository);

            Assert.IsFalse(result.IsValid);
        }
Пример #7
0
        public async Task IsValid_ReturnsOkIfJenkinsFileHasNoPtcsLibrary()
        {
            var content = CreateContent("JENKINSFILE", "random content");
            IReadOnlyList <RepositoryContent> contents = new[] { content };

            var repository = CreateRepository("repomen");

            MockRepositoryContentClient.GetAllContentsByRef(Owner.Name, repository.Name, MainBranch).Returns(Task.FromResult(contents));
            MockRepositoryContentClient.GetAllContentsByRef(Owner.Name, repository.Name, contents[0].Name, MainBranch).Returns(Task.FromResult(contents));

            var result = await _rule.IsValid(MockClient, repository);

            Assert.IsTrue(result.IsValid);
        }
Пример #8
0
        public async Task IsValid_IgnoresCommentedLibraryVersionButNotActual()
        {
            var content = CreateContent("JENKINSFILE", "//Actual version may be library '[email protected]'" + Environment.NewLine + $"library '[email protected]'");

            IReadOnlyList <RepositoryContent> contents = new[] { content };
            var repository = CreateRepository("repo");

            MockRepositoryContentClient.GetAllContentsByRef(Owner.Name, repository.Name, MainBranch).Returns(Task.FromResult(contents));
            MockRepositoryContentClient.GetAllContentsByRef(Owner.Name, repository.Name, contents[0].Name, MainBranch).Returns(Task.FromResult(contents));

            var result = await _rule.IsValid(MockClient, repository);

            Assert.IsFalse(result.IsValid);
        }
Пример #9
0
        public async Task IsValid_ReturnsFalseIfCodeownersFileEmpty()
        {
            var content = CreateContent("CODEOWNERS", "");
            IReadOnlyList <RepositoryContent> contents = new[] { content };

            var repository = CreateRepository("repo");

            MockRepositoryContentClient.GetAllContentsByRef(Owner.Name, repository.Name, MainBranch).Returns(Task.FromResult(contents));
            MockRepositoryContentClient.GetAllContentsByRef(Owner.Name, repository.Name, contents[0].Name, MainBranch).Returns(Task.FromResult(contents));

            var result = await _rule.IsValid(MockClient, repository);

            StringAssert.AreEqualIgnoringCase(result.HowToFix, "Add CODEOWNERS file & add at least one owner.");
            Assert.IsFalse(result.IsValid);
        }
Пример #10
0
        public async Task IsValid_ReturnsTrueIfCodeownersFileExistsInGithubDirectoryAndHasAtleastOneEntry()
        {
            var directory = CreateRepositoryDirectory(".github");
            IReadOnlyList <RepositoryContent> rootContents = new[] { directory };

            var content = CreateContent("CODEOWNERS", "devguy");
            IReadOnlyList <RepositoryContent> contents = new[] { content };

            var repository = CreateRepository("repo");

            MockRepositoryContentClient.GetAllContentsByRef(Owner.Name, repository.Name, MainBranch).Returns(Task.FromResult(rootContents));
            MockRepositoryContentClient.GetAllContentsByRef(Owner.Name, repository.Name, rootContents[0].Name, MainBranch).Returns(Task.FromResult(contents));
            MockRepositoryContentClient.GetAllContentsByRef(Owner.Name, repository.Name, rootContents[0].Name + "/" + contents[0].Name, MainBranch).Returns(Task.FromResult(contents));

            var result = await _rule.IsValid(MockClient, repository);

            Assert.IsTrue(result.IsValid);
        }
Пример #11
0
        public async Task IsValid_ReturnsFalseWhenReadmeDoesNotExist([Values("aREADME.md", "rEaDmE.txta", "README.", "readm", "ReAdMea.doc", "")] string readMeName)
        {
            var contents = new List <RepositoryContent>();

            if (!string.IsNullOrEmpty(readMeName))
            {
                var readme = CreateContent(readMeName, "random content");
                contents.Add(readme);
            }
            var repository = CreateRepository("repomen");

            if (contents.Count != 0)
            {
                MockRepositoryContentClient.GetAllContentsByRef(Owner.Name, repository.Name, contents[0].Name, MainBranch).Returns(Task.FromResult((IReadOnlyList <RepositoryContent>)contents));
            }
            MockRepositoryContentClient.GetAllContentsByRef(Owner.Name, repository.Name, MainBranch).Returns(Task.FromResult((IReadOnlyList <RepositoryContent>)contents));

            var result = await _rule.IsValid(MockClient, repository);

            Assert.IsFalse(result.IsValid);
        }