You've already forked go-semantic-release
test(releaser/github): tests for GetCommitURL(), GetCompareURL(), ValisateConfig()
This commit is contained in:
@@ -1,29 +1,55 @@
|
|||||||
package github_test
|
package github_test
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
|
"os"
|
||||||
|
"testing"
|
||||||
|
|
||||||
"github.com/Nightapes/go-semantic-release/internal/releaser/github"
|
"github.com/Nightapes/go-semantic-release/internal/releaser/github"
|
||||||
"github.com/Nightapes/go-semantic-release/pkg/config"
|
"github.com/Nightapes/go-semantic-release/pkg/config"
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
"os"
|
|
||||||
"testing"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type testDoubleNew struct {
|
type testDouble struct {
|
||||||
config config.GitHubProvider
|
config config.GitHubProvider
|
||||||
valid bool
|
valid bool
|
||||||
}
|
}
|
||||||
|
|
||||||
var doublesNew = []testDoubleNew{
|
var doublesNew = []testDouble{
|
||||||
testDoubleNew{config: config.GitHubProvider{
|
testDouble{config: config.GitHubProvider{
|
||||||
Repo: "foo",
|
Repo: "foo",
|
||||||
User: "bar",
|
User: "bar",
|
||||||
},
|
},
|
||||||
valid: true,
|
valid: true,
|
||||||
},
|
},
|
||||||
|
|
||||||
testDoubleNew{config: config.GitHubProvider{
|
testDouble{config: config.GitHubProvider{
|
||||||
Repo: "foo",
|
Repo: "foo",
|
||||||
User: "bar",
|
User: "bar",
|
||||||
|
CustomURL: "https://test.com",
|
||||||
|
},
|
||||||
|
valid: false,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
var doublesValidateConfig = []testDouble{
|
||||||
|
testDouble{config: config.GitHubProvider{
|
||||||
|
Repo: "foo",
|
||||||
|
User: "bar",
|
||||||
|
},
|
||||||
|
valid: true,
|
||||||
|
},
|
||||||
|
|
||||||
|
testDouble{config: config.GitHubProvider{
|
||||||
|
Repo: "",
|
||||||
|
User: "bar",
|
||||||
|
},
|
||||||
|
valid: false,
|
||||||
|
},
|
||||||
|
|
||||||
|
testDouble{config: config.GitHubProvider{
|
||||||
|
Repo: "foo",
|
||||||
|
User: "",
|
||||||
},
|
},
|
||||||
valid: false,
|
valid: false,
|
||||||
},
|
},
|
||||||
@@ -42,3 +68,51 @@ func TestNew(t *testing.T) {
|
|||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestGetCommitURL(t *testing.T) {
|
||||||
|
os.Setenv("GITHUB_ACCESS_TOKEN", "XX")
|
||||||
|
for _, testOject := range doublesNew {
|
||||||
|
client, _ := github.New(&testOject.config)
|
||||||
|
actualUrl := client.GetCommitURL()
|
||||||
|
if testOject.config.CustomURL != "" {
|
||||||
|
expectedUrl := fmt.Sprintf("%s/%s/%s/commit/{{hash}}", testOject.config.CustomURL, testOject.config.User, testOject.config.Repo)
|
||||||
|
assert.EqualValues(t, expectedUrl, actualUrl)
|
||||||
|
|
||||||
|
} else {
|
||||||
|
expectedUrl := fmt.Sprintf("%s/%s/%s/commit/{{hash}}", "https://github.com", testOject.config.User, testOject.config.Repo)
|
||||||
|
assert.EqualValues(t, expectedUrl, actualUrl)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
os.Unsetenv("GITHUB_ACCESS_TOKEN")
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestGetCompareURL(t *testing.T) {
|
||||||
|
os.Setenv("GITHUB_ACCESS_TOKEN", "XX")
|
||||||
|
for _, testOject := range doublesNew {
|
||||||
|
client, _ := github.New(&testOject.config)
|
||||||
|
actualUrl := client.GetCompareURL("1", "2")
|
||||||
|
if testOject.config.CustomURL != "" {
|
||||||
|
expectedUrl := fmt.Sprintf("%s/%s/%s/compare/%s...%s", testOject.config.CustomURL, testOject.config.User, testOject.config.Repo, "1", "2")
|
||||||
|
assert.EqualValues(t, expectedUrl, actualUrl)
|
||||||
|
|
||||||
|
} else {
|
||||||
|
expectedUrl := fmt.Sprintf("%s/%s/%s/compare/%s...%s", "https://github.com", testOject.config.User, testOject.config.Repo, "1", "2")
|
||||||
|
assert.EqualValues(t, expectedUrl, actualUrl)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
os.Unsetenv("GITHUB_ACCESS_TOKEN")
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestValidateConfig(t *testing.T) {
|
||||||
|
os.Setenv("GITHUB_ACCESS_TOKEN", "XX")
|
||||||
|
for _, testOject := range doublesValidateConfig {
|
||||||
|
client, _ := github.New(&testOject.config)
|
||||||
|
err := client.ValidateConfig()
|
||||||
|
|
||||||
|
assert.Equal(t, testOject.valid, err == nil)
|
||||||
|
|
||||||
|
}
|
||||||
|
os.Unsetenv("GITHUB_ACCESS_TOKEN")
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user