1
0
mirror of https://github.com/goreleaser/goreleaser.git synced 2025-03-19 20:57:53 +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) { func TestCheckUseJobToken(t *testing.T) {
tests := []struct { tests := []struct {
ctx context.Context useJobToken bool
token string token string
ciToken string ciToken string
want bool want bool
desc string desc string
name string
}{ }{
{ {
ctx: context.Context{ useJobToken: true,
Config: config.Project{ token: "real-ci-token",
GitLabURLs: config.GitLabURLs{ ciToken: "real-ci-token",
UseJobToken: true, desc: "token and CI_JOB_TOKEN match so should return true",
}, want: true,
}, name: "UseJobToken-tokens-equal",
},
token: "real-ci-token",
ciToken: "real-ci-token",
desc: "token and CI_JOB_TOKEN match so should return true",
want: true,
}, },
{ {
ctx: context.Context{ useJobToken: true,
Config: config.Project{ token: "some-random-token",
GitLabURLs: config.GitLabURLs{ ciToken: "real-ci-token",
UseJobToken: true, desc: "token and CI_JOB_TOKEN do NOT match so should return false",
}, want: false,
}, name: "UseJobToken-tokens-diff",
},
token: "some-random-token",
ciToken: "real-ci-token",
desc: "token and CI_JOB_TOKEN do NOT match so should return false",
want: false,
}, },
{ {
ctx: context.Context{ useJobToken: false,
Config: config.Project{ token: "real-ci-token",
GitLabURLs: config.GitLabURLs{ ciToken: "real-ci-token",
UseJobToken: false, desc: "token and CI_JOB_TOKEN match, however UseJobToken is set to false, so return false",
}, want: false,
}, name: "NoUseJobToken-tokens-equal",
}, },
token: "real-ci-token", {
ciToken: "real-ci-token", useJobToken: false,
desc: "token and CI_JOB_TOKEN match, however UseJobToken is set to false, so return false", token: "real-ci-token",
want: false, 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 { for _, tt := range tests {
t.Setenv("CI_JOB_TOKEN", tt.ciToken) t.Run(tt.name, func(t *testing.T) {
got := checkUseJobToken(tt.ctx, tt.token) t.Setenv("CI_JOB_TOKEN", tt.ciToken)
require.Equal(t, tt.want, got, tt.desc) ctx := context.New(config.Project{
GitLabURLs: config.GitLabURLs{
UseJobToken: tt.useJobToken,
},
})
got := checkUseJobToken(ctx, tt.token)
require.Equal(t, tt.want, got, tt.desc)
})
} }
} }