From 2e7d37a1c50ad90d33fe2a0a94e647fb01232dfe Mon Sep 17 00:00:00 2001 From: Naveen <172697+naveensrinivasan@users.noreply.github.com> Date: Wed, 26 Jul 2023 15:27:36 -0500 Subject: [PATCH] :seedling: Improve `gitlabrepo.ListProgrammingLanguages` e2e tests (#3309) * :seedling: Improve `gitlabrepo.ListProgrammingLanguages` e2e tests - Add an end-to-end test for the `gitlabrepo.ListProgrammingLanguages` function - Include a test for repos without code to check that no programming languages are returned [clients/gitlabrepo/languages_e2e_test.go] - Add an e2e test for the `gitlabrepo.ListProgrammingLanguages` function - Add a test for repos without code to check that no programming languages are returned Signed-off-by: naveensrinivasan <172697+naveensrinivasan@users.noreply.github.com> * Increase test accuracy for language e2e tests - Lower the numeric tolerance for e2e tests in the GitLab repository [clients/gitlabrepo/languages_e2e_test.go] - Lower numeric tolerance for test files Signed-off-by: naveensrinivasan <172697+naveensrinivasan@users.noreply.github.com> --------- Signed-off-by: naveensrinivasan <172697+naveensrinivasan@users.noreply.github.com> --- clients/gitlabrepo/languages_e2e_test.go | 64 ++++++++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100644 clients/gitlabrepo/languages_e2e_test.go diff --git a/clients/gitlabrepo/languages_e2e_test.go b/clients/gitlabrepo/languages_e2e_test.go new file mode 100644 index 00000000000..2e16a460707 --- /dev/null +++ b/clients/gitlabrepo/languages_e2e_test.go @@ -0,0 +1,64 @@ +// Copyright 2023 OpenSSF Scorecard Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package gitlabrepo + +import ( + "context" + "strings" + + . "github.com/onsi/ginkgo/v2" + . "github.com/onsi/gomega" +) + +var _ = Describe("E2E TEST: gitlabrepo.ListProgrammingLanguages", func() { + Context("Test list programming languages - GitLab", func() { + It("returns branches for the repo", func() { + repo, err := MakeGitlabRepo("https://gitlab.com/baserow/baserow") + Expect(err).Should(BeNil()) + + client, err := CreateGitlabClient(context.Background(), repo.Host()) + Expect(err).Should(BeNil()) + + err = client.InitRepo(repo, "HEAD", 0) + Expect(err).Should(BeNil()) + programmingLang, err := client.ListProgrammingLanguages() + Expect(err).Should(BeNil()) + Expect(programmingLang).ShouldNot(BeNil()) + // Check for the presence of some languages + isPythonPresent := false + for _, lang := range programmingLang { + // compare case insensitive + if strings.EqualFold(string(lang.Name), "Python") { + isPythonPresent = true + break + } + } + Expect(isPythonPresent).Should(BeTrue()) + }) + It("Should return no programming languages repo with no code", func() { + repo, err := MakeGitlabRepo("https://gitlab.com/ossf-test/scorecard-test-branches") + Expect(err).Should(BeNil()) + + client, err := CreateGitlabClient(context.Background(), repo.Host()) + Expect(err).Should(BeNil()) + + err = client.InitRepo(repo, "HEAD", 0) + Expect(err).Should(BeNil()) + programmingLang, err := client.ListProgrammingLanguages() + Expect(err).Should(BeNil()) + Expect(programmingLang).Should(BeNil()) + }) + }) +})