-
Notifications
You must be signed in to change notification settings - Fork 22
/
git_test.go
41 lines (36 loc) · 2.44 KB
/
git_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
package main
import (
"testing"
"github.com/jfrog/jfrog-cli-security/commands/git"
securityTests "github.com/jfrog/jfrog-cli-security/tests"
"github.com/jfrog/jfrog-cli-security/tests/utils/integration"
"github.com/jfrog/jfrog-client-go/utils/tests"
"github.com/stretchr/testify/assert"
)
func TestCountContributorsFlags(t *testing.T) {
integration.InitGitTest(t)
err := securityTests.PlatformCli.WithoutCredentials().Exec("git", "count-contributors", "--token", "token", "--owner", "owner", "--scm-api-url", "url")
assert.EqualError(t, err, "Mandatory flag 'scm-type' is missing")
err = securityTests.PlatformCli.WithoutCredentials().Exec("git", "cc", "--scm-type", "github", "--owner", "owner", "--scm-api-url", "url")
assert.ErrorContains(t, err, "Mandatory flag 'token' is missing")
err = securityTests.PlatformCli.WithoutCredentials().Exec("git", "cc", "--scm-type", "gitlab", "--token", "token", "--scm-api-url", "url")
assert.EqualError(t, err, "Mandatory flag 'owner' is missing")
err = securityTests.PlatformCli.WithoutCredentials().Exec("git", "cc", "--scm-type", "bitbucket", "--token", "token", "--owner", "owner")
assert.EqualError(t, err, "Mandatory flag 'scm-api-url' is missing")
// Test token env variable
bitbucketCallback := tests.SetEnvWithCallbackAndAssert(t, git.BitbucketTokenEnvVar, "token")
err = securityTests.PlatformCli.WithoutCredentials().Exec("git", "count-contributors", "--scm-type", "bitbucket", "--owner", "owner", "--scm-api-url", "url")
assert.NotContains(t, err.Error(), "Providing a token is mandatory")
bitbucketCallback()
gitlabCallback := tests.SetEnvWithCallbackAndAssert(t, git.GitlabTokenEnvVar, "token")
err = securityTests.PlatformCli.WithoutCredentials().Exec("git", "count-contributors", "--scm-type", "gitlab", "--owner", "owner", "--scm-api-url", "url")
assert.NotContains(t, err.Error(), "Providing a token is mandatory")
gitlabCallback()
githubCallback := tests.SetEnvWithCallbackAndAssert(t, git.GithubTokenEnvVar, "token")
err = securityTests.PlatformCli.WithoutCredentials().Exec("git", "count-contributors", "--scm-type", "github", "--owner", "owner", "--scm-api-url", "url")
assert.NotContains(t, err.Error(), "Providing a token is mandatory")
githubCallback()
// Test unsupported scm type
err = securityTests.PlatformCli.WithoutCredentials().Exec("git", "cc", "--scm-type", "bad-type", "--token", "token", "--owner", "owner", "--scm-api-url", "url")
assert.ErrorContains(t, err, "Unsupported SCM type")
}