diff --git a/Makefile b/Makefile index b9d5e4c8509..9f8eccc49f1 100644 --- a/Makefile +++ b/Makefile @@ -335,7 +335,7 @@ e2e-gh-token: build-scorecard check-env | $(GINKGO) 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 - TOKEN_TYPE="GITLAB_PAT" $(GINKGO) --race -p -vv --focus '.*GitLab Token' ./... + TEST_GITLAB_EXTERNAL=1 TOKEN_TYPE="GITLAB_PAT" $(GINKGO) --race -p -vv --focus '.*GitLab Token' ./... e2e-gitlab: ## Runs e2e tests for GitLab only. TOKEN_TYPE is not used (since these are public APIs), but must be set to something TOKEN_TYPE="GITLAB_PAT" $(GINKGO) --race -p -vv --focus '.*GitLab' ./... diff --git a/clients/gitlabrepo/repo_test.go b/clients/gitlabrepo/repo_test.go index de99f02b1e1..798be39d0bf 100644 --- a/clients/gitlabrepo/repo_test.go +++ b/clients/gitlabrepo/repo_test.go @@ -16,6 +16,7 @@ package gitlabrepo import ( "fmt" + "os" "testing" "github.com/google/go-cmp/cmp" @@ -25,10 +26,11 @@ import ( func TestRepoURL_IsValid(t *testing.T) { t.Parallel() tests := []struct { - name string - inputURL string - expected repoURL - wantErr bool + name string + inputURL string + expected repoURL + wantErr bool + flagRequired bool }{ { name: "github repository", @@ -73,7 +75,6 @@ func TestRepoURL_IsValid(t *testing.T) { inputURL: "https://gitlab.com/ossf-test/scorecard-check-binary-artifacts-e2e/", wantErr: false, }, - { name: "valid hosted gitlab project", expected: repoURL{ @@ -82,12 +83,16 @@ func TestRepoURL_IsValid(t *testing.T) { owner: "webmaster-team", project: "webml", }, - inputURL: "https://salsa.debian.org/webmaster-team/webwml", - wantErr: false, + inputURL: "https://salsa.debian.org/webmaster-team/webwml", + wantErr: false, + flagRequired: true, }, } for _, tt := range tests { tt := tt // Re-initializing variable so it is not changed while executing the closure blow + if tt.flagRequired && os.Getenv("TEST_GITLAB_EXTERNAL") == "" { + continue + } t.Run(tt.name, func(t *testing.T) { t.Parallel() r := repoURL{ @@ -116,8 +121,9 @@ func TestRepoURL_IsValid(t *testing.T) { func TestRepoURL_DetectGitlab(t *testing.T) { tests := []struct { - repouri string - expected bool + repouri string + expected bool + flagRequired bool }{ { repouri: "github.com/ossf/scorecard", @@ -136,8 +142,9 @@ func TestRepoURL_DetectGitlab(t *testing.T) { expected: true, }, { - repouri: "https://salsa.debian.org/webmaster-team/webml", - expected: true, + repouri: "https://salsa.debian.org/webmaster-team/webml", + expected: true, + flagRequired: true, }, { // Invalid repo @@ -147,6 +154,9 @@ func TestRepoURL_DetectGitlab(t *testing.T) { } for _, tt := range tests { + if tt.flagRequired && os.Getenv("TEST_GITLAB_EXTERNAL") == "" { + continue + } g := DetectGitLab(tt.repouri) if g != tt.expected { t.Errorf("got %s isgitlab: %t expected %t", tt.repouri, g, tt.expected)