1
0
mirror of https://github.com/goreleaser/goreleaser.git synced 2025-03-17 20:47:50 +02:00

test: improve gitlab tests

This commit is contained in:
Carlos A Becker 2022-09-30 20:20:33 -03:00
parent 7f3cef0c2d
commit cf06b08983
No known key found for this signature in database
GPG Key ID: E61E2F7DC14AB940

View File

@ -549,55 +549,56 @@ func TestCloseMileston(t *testing.T) {
func TestCheckUseJobToken(t *testing.T) {
tests := []struct {
ctx context.Context
useJobToken bool
token string
ciToken string
want bool
desc string
name string
}{
{
ctx: context.Context{
Config: config.Project{
GitLabURLs: config.GitLabURLs{
UseJobToken: true,
},
},
},
useJobToken: true,
token: "real-ci-token",
ciToken: "real-ci-token",
desc: "token and CI_JOB_TOKEN match so should return true",
want: true,
name: "UseJobToken-tokens-equal",
},
{
ctx: context.Context{
Config: config.Project{
GitLabURLs: config.GitLabURLs{
UseJobToken: true,
},
},
},
useJobToken: true,
token: "some-random-token",
ciToken: "real-ci-token",
desc: "token and CI_JOB_TOKEN do NOT match so should return false",
want: false,
name: "UseJobToken-tokens-diff",
},
{
ctx: context.Context{
Config: config.Project{
GitLabURLs: config.GitLabURLs{
UseJobToken: false,
},
},
},
useJobToken: false,
token: "real-ci-token",
ciToken: "real-ci-token",
desc: "token and CI_JOB_TOKEN match, however UseJobToken is set to false, so return false",
want: false,
name: "NoUseJobToken-tokens-equal",
},
{
useJobToken: false,
token: "real-ci-token",
ciToken: "real-ci-token",
desc: "token and CI_JOB_TOKEN do not match, and UseJobToken is set to false, should return false",
want: false,
name: "NoUseJobToken-tokens-diff",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
t.Setenv("CI_JOB_TOKEN", tt.ciToken)
got := checkUseJobToken(tt.ctx, tt.token)
ctx := context.New(config.Project{
GitLabURLs: config.GitLabURLs{
UseJobToken: tt.useJobToken,
},
})
got := checkUseJobToken(ctx, tt.token)
require.Equal(t, tt.want, got, tt.desc)
})
}
}