mirror of
https://github.com/ossf/scorecard.git
synced 2024-08-16 11:50:37 +03:00
🌱 Gitlab: Move tests that connect to gitlab.com out of unit-tests (#3221)
* Move tests that connect to GitLab out of e2e Signed-off-by: Raghav Kaul <raghavkaul@google.com> * update Signed-off-by: Raghav Kaul <raghavkaul@google.com> * mark as pat test Signed-off-by: Raghav Kaul <raghavkaul@google.com> --------- Signed-off-by: Raghav Kaul <raghavkaul@google.com>
This commit is contained in:
parent
b2bc681a00
commit
c72cfd5d32
2
Makefile
2
Makefile
@ -341,7 +341,7 @@ e2e-pat: build-scorecard check-env | $(GINKGO)
|
||||
e2e-gh-token: ## Runs e2e tests. Requires GITHUB_AUTH_TOKEN env var to be set to default GITHUB_TOKEN
|
||||
e2e-gh-token: build-scorecard check-env | $(GINKGO)
|
||||
# Run e2e tests. GITHUB_AUTH_TOKEN set to secrets.GITHUB_TOKEN must be used to run this.
|
||||
TOKEN_TYPE="GITHUB_TOKEN" $(GINKGO) --race -p -v -cover -coverprofile=e2e-coverage.out --keep-separate-coverprofiles ./...
|
||||
GITLAB_AUTH_TOKEN="" TOKEN_TYPE="GITHUB_TOKEN" $(GINKGO) --race -p -v -cover -coverprofile=e2e-coverage.out --keep-separate-coverprofiles ./...
|
||||
|
||||
e2e-gitlab-token: ## Runs e2e tests that require a GITLAB_TOKEN
|
||||
e2e-gitlab-token: build-scorecard check-env-gitlab | $(GINKGO)
|
||||
|
75
clients/gitlabrepo/commits_e2e_test.go
Normal file
75
clients/gitlabrepo/commits_e2e_test.go
Normal file
@ -0,0 +1,75 @@
|
||||
// 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"
|
||||
"fmt"
|
||||
"os"
|
||||
|
||||
. "github.com/onsi/ginkgo/v2"
|
||||
. "github.com/onsi/gomega"
|
||||
)
|
||||
|
||||
type tokenType int
|
||||
|
||||
const (
|
||||
patTokenType tokenType = iota
|
||||
githubWorkflowDefaultTokenType
|
||||
gitlabPATTokenType
|
||||
)
|
||||
|
||||
var tokType tokenType
|
||||
|
||||
func skipIfTokenIsNot(t tokenType, msg string) {
|
||||
if tokType != t {
|
||||
Skip(msg)
|
||||
}
|
||||
}
|
||||
|
||||
var _ = BeforeSuite(func() {
|
||||
tt := os.Getenv("TOKEN_TYPE")
|
||||
switch tt {
|
||||
case "PAT":
|
||||
tokType = patTokenType
|
||||
case "GITHUB_TOKEN":
|
||||
tokType = githubWorkflowDefaultTokenType
|
||||
case "GITLAB_PAT":
|
||||
tokType = gitlabPATTokenType
|
||||
default:
|
||||
panic(fmt.Sprintf("invalid TOKEN_TYPE: %s", tt))
|
||||
}
|
||||
})
|
||||
|
||||
var _ = Describe("E2E TEST: gitlabrepo.commitsHandler", func() {
|
||||
Context("ListCommits", func() {
|
||||
It("Checks whether commits are listed - GitLab", func() {
|
||||
skipIfTokenIsNot(patTokenType, "PAT only")
|
||||
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, "8a38c9f724c19b5422e27864a108318d1f769b8a", 20)
|
||||
Expect(err).Should(BeNil())
|
||||
|
||||
c, err := client.ListCommits()
|
||||
Expect(err).Should(BeNil())
|
||||
|
||||
Expect(len(c)).Should(BeNumerically(">", 0))
|
||||
})
|
||||
})
|
||||
})
|
@ -15,54 +15,9 @@
|
||||
package gitlabrepo
|
||||
|
||||
import (
|
||||
"context"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func Test_Setup(t *testing.T) {
|
||||
t.Parallel()
|
||||
tcs := []struct {
|
||||
name string
|
||||
repourl string
|
||||
commit string
|
||||
depth int
|
||||
}{
|
||||
{
|
||||
name: "check that listcommits works",
|
||||
repourl: "https://gitlab.com/fdroid/fdroidclient",
|
||||
commit: "a4bbef5c70fd2ac7c15437a22ef0f9ef0b447d08",
|
||||
depth: 20,
|
||||
},
|
||||
}
|
||||
|
||||
for _, tt := range tcs {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
repo, err := MakeGitlabRepo(tt.repourl)
|
||||
if err != nil {
|
||||
t.Error("couldn't make gitlab repo", err)
|
||||
}
|
||||
|
||||
client, err := CreateGitlabClient(context.Background(), repo.Host())
|
||||
if err != nil {
|
||||
t.Error("couldn't make gitlab client", err)
|
||||
}
|
||||
|
||||
err = client.InitRepo(repo, tt.commit, tt.depth)
|
||||
if err != nil {
|
||||
t.Error("couldn't init gitlab repo", err)
|
||||
}
|
||||
|
||||
c, err := client.ListCommits()
|
||||
if err != nil {
|
||||
t.Error("couldn't list gitlab repo commits", err)
|
||||
}
|
||||
if len(c) == 0 {
|
||||
t.Error("couldn't get any commits from gitlab repo")
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestParsingEmail(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
|
@ -15,66 +15,13 @@
|
||||
package gitlabrepo
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"strconv"
|
||||
"strings"
|
||||
"sync"
|
||||
"testing"
|
||||
|
||||
"github.com/xanzy/go-gitlab"
|
||||
)
|
||||
|
||||
func Test_ContributorsSetup(t *testing.T) {
|
||||
t.Parallel()
|
||||
tcs := []struct {
|
||||
name string
|
||||
repourl string
|
||||
commit string
|
||||
depth int
|
||||
}{
|
||||
{
|
||||
name: "check that Contributor works",
|
||||
repourl: "https://gitlab.com/fdroid/fdroidclient",
|
||||
commit: "HEAD",
|
||||
depth: 20,
|
||||
},
|
||||
}
|
||||
|
||||
for _, tt := range tcs {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
repo, err := MakeGitlabRepo(tt.repourl)
|
||||
if err != nil {
|
||||
t.Error("couldn't make gitlab repo", err)
|
||||
}
|
||||
|
||||
client, err := CreateGitlabClientWithToken(context.Background(), "", repo.Host())
|
||||
if err != nil {
|
||||
t.Error("couldn't make gitlab client", err)
|
||||
}
|
||||
|
||||
err = client.InitRepo(repo, tt.commit, tt.depth)
|
||||
if err != nil {
|
||||
t.Error("couldn't init gitlab repo",
|
||||
err)
|
||||
}
|
||||
|
||||
c, err := client.ListContributors()
|
||||
// Authentication is failing when querying users, not sure yet how to get around that
|
||||
if err != nil {
|
||||
errMsg := fmt.Sprintf("%v", err)
|
||||
|
||||
if !(strings.Contains(errMsg, "error during Users.Get") && strings.Contains(errMsg, "401")) {
|
||||
t.Error("couldn't list gitlab repo contributors", err)
|
||||
}
|
||||
}
|
||||
if len(c) != 0 {
|
||||
t.Error("couldn't get any contributors from gitlab repo")
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestContributors(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
|
@ -16,6 +16,8 @@ package e2e
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
. "github.com/onsi/ginkgo/v2"
|
||||
. "github.com/onsi/gomega"
|
||||
@ -24,6 +26,7 @@ import (
|
||||
"github.com/ossf/scorecard/v4/checks"
|
||||
"github.com/ossf/scorecard/v4/clients"
|
||||
"github.com/ossf/scorecard/v4/clients/githubrepo"
|
||||
"github.com/ossf/scorecard/v4/clients/gitlabrepo"
|
||||
scut "github.com/ossf/scorecard/v4/utests"
|
||||
)
|
||||
|
||||
@ -54,5 +57,28 @@ var _ = Describe("E2E TEST:"+checks.CheckContributors, func() {
|
||||
Expect(scut.ValidateTestReturn(nil, "several contributors", &expected, &result, &dl)).Should(BeTrue())
|
||||
Expect(repoClient.Close()).Should(BeNil())
|
||||
})
|
||||
|
||||
It("Should return valid project contributors - GitLab", func() {
|
||||
skipIfTokenIsNot(gitlabPATTokenType, "PAT only")
|
||||
repo, err := gitlabrepo.MakeGitlabRepo("https://gitlab.com/baserow/baserow")
|
||||
Expect(err).Should(BeNil())
|
||||
|
||||
client, err := gitlabrepo.CreateGitlabClient(context.Background(), repo.Host())
|
||||
Expect(err).Should(BeNil())
|
||||
|
||||
err = client.InitRepo(repo, "HEAD", 20)
|
||||
Expect(err).Should(BeNil())
|
||||
|
||||
c, err := client.ListContributors()
|
||||
// Authentication is failing when querying users, not sure yet how to get around that
|
||||
if err != nil {
|
||||
errMsg := fmt.Sprintf("%v", err)
|
||||
|
||||
if !(strings.Contains(errMsg, "error during Users.Get") && strings.Contains(errMsg, "401")) {
|
||||
Fail(fmt.Sprintf("couldn't list gitlab repo contributors: %v", err))
|
||||
}
|
||||
}
|
||||
Expect(len(c)).Should(BeNumerically(">", 0))
|
||||
})
|
||||
})
|
||||
})
|
||||
|
Loading…
Reference in New Issue
Block a user