You've already forked go-semantic-release
test(ci services): add test for travis
This commit is contained in:
86
internal/ci/ci_test.go
Normal file
86
internal/ci/ci_test.go
Normal file
@@ -0,0 +1,86 @@
|
||||
package ci_test
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/Nightapes/go-semantic-release/internal/ci"
|
||||
"github.com/Nightapes/go-semantic-release/internal/gitutil"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"gopkg.in/src-d/go-git.v4"
|
||||
"gopkg.in/src-d/go-git.v4/storage/memory"
|
||||
"os"
|
||||
)
|
||||
|
||||
func TestSum(t *testing.T) {
|
||||
testConfigs := []struct {
|
||||
service string
|
||||
envs map[string]string
|
||||
result *ci.ProviderConfig
|
||||
hasError bool
|
||||
}{
|
||||
{
|
||||
service: "none",
|
||||
envs: map[string]string{},
|
||||
result: nil,
|
||||
hasError: true,
|
||||
},
|
||||
// {
|
||||
// service: "Git",
|
||||
// envs: map[string]string{
|
||||
// "CI": "true",
|
||||
// },
|
||||
// result: &ci.ProviderConfig{IsPR: true, PR: "10", PRBranch: "pr", Branch: "master", Tag: "TAG", Commit: "190bfd6aa60022afd0ef830342cfb07e33c45f37", BuildURL: "https://travis-ci.com/owner/repo/builds/1234", Service: "travis", Name: "Travis CI"},
|
||||
// hasError: false,
|
||||
// },
|
||||
{
|
||||
service: "Travis PR",
|
||||
envs: map[string]string{
|
||||
"TRAVIS": "true",
|
||||
"TRAVIS_PULL_REQUEST": "10",
|
||||
"TRAVIS_COMMIT": "190bfd6aa60022afd0ef830342cfb07e33c45f37",
|
||||
"TRAVIS_TAG": "TAG",
|
||||
"TRAVIS_BUILD_WEB_URL": "https://travis-ci.com/owner/repo/builds/1234",
|
||||
"TRAVIS_BRANCH": "master",
|
||||
"TRAVIS_PULL_REQUEST_BRANCH": "pr",
|
||||
},
|
||||
result: &ci.ProviderConfig{IsPR: true, PR: "10", PRBranch: "pr", Branch: "master", Tag: "TAG", Commit: "190bfd6aa60022afd0ef830342cfb07e33c45f37", BuildURL: "https://travis-ci.com/owner/repo/builds/1234", Service: "travis", Name: "Travis CI"},
|
||||
hasError: false,
|
||||
},
|
||||
{
|
||||
service: "Travis Push",
|
||||
envs: map[string]string{
|
||||
"TRAVIS": "true",
|
||||
"TRAVIS_PULL_REQUEST": "false",
|
||||
"TRAVIS_COMMIT": "190bfd6aa60022afd0ef830342cfb07e33c45f37",
|
||||
"TRAVIS_TAG": "TAG",
|
||||
"TRAVIS_BUILD_WEB_URL": "https://travis-ci.com/owner/repo/builds/1234",
|
||||
"TRAVIS_BRANCH": "master",
|
||||
},
|
||||
result: &ci.ProviderConfig{IsPR: false, PR: "", PRBranch: "", Branch: "master", Tag: "TAG", Commit: "190bfd6aa60022afd0ef830342cfb07e33c45f37", BuildURL: "https://travis-ci.com/owner/repo/builds/1234", Service: "travis", Name: "Travis CI"},
|
||||
hasError: false,
|
||||
},
|
||||
}
|
||||
|
||||
repository, err := git.Init(memory.NewStorage(), nil)
|
||||
assert.NoError(t, err, "should open git repository")
|
||||
|
||||
gitUtilInMemory := &gitutil.GitUtil{
|
||||
Repository: repository,
|
||||
}
|
||||
|
||||
for _, config := range testConfigs {
|
||||
|
||||
for key, value := range config.envs {
|
||||
os.Setenv(key, value)
|
||||
}
|
||||
|
||||
provider, err := ci.GetCIProvider(gitUtilInMemory)
|
||||
assert.Equalf(t, config.hasError, err != nil, "Service %s should have error: %t -> %s", config.service, config.hasError, err)
|
||||
assert.Equalf(t, config.result, provider, "Service %s should have provider", config.service)
|
||||
|
||||
for key, _ := range config.envs {
|
||||
os.Unsetenv(key)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user