test(github): merge incoming changes

This commit is contained in:
Nightapes
2019-08-08 20:22:49 +02:00

View File

@@ -7,21 +7,22 @@ import (
"os" "os"
"testing" "testing"
log "github.com/sirupsen/logrus"
"github.com/Masterminds/semver" "github.com/Masterminds/semver"
"github.com/Nightapes/go-semantic-release/internal/releaser/github" "github.com/Nightapes/go-semantic-release/internal/releaser/github"
"github.com/Nightapes/go-semantic-release/internal/shared" "github.com/Nightapes/go-semantic-release/internal/shared"
"github.com/Nightapes/go-semantic-release/pkg/config" "github.com/Nightapes/go-semantic-release/pkg/config"
log "github.com/sirupsen/logrus"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
) )
type testDouble struct { type testHelperMethodStruct struct {
config config.GitHubProvider config config.GitHubProvider
valid bool valid bool
} }
type testFourth struct { type testReleaseStruct struct {
config config.GitHubProvider config config.GitHubProvider
releaseVersion *shared.ReleaseVersion releaseVersion *shared.ReleaseVersion
generatedChangelog *shared.GeneratedChangelog generatedChangelog *shared.GeneratedChangelog
@@ -30,15 +31,15 @@ type testFourth struct {
valid bool valid bool
} }
var doublesNew = []testDouble{ var testNewClient = []testHelperMethodStruct{
testDouble{config: config.GitHubProvider{ testHelperMethodStruct{config: config.GitHubProvider{
Repo: "foo", Repo: "foo",
User: "bar", User: "bar",
}, },
valid: true, valid: true,
}, },
testDouble{config: config.GitHubProvider{ testHelperMethodStruct{config: config.GitHubProvider{
Repo: "foo", Repo: "foo",
User: "bar", User: "bar",
CustomURL: "https://test.com", CustomURL: "https://test.com",
@@ -47,22 +48,22 @@ var doublesNew = []testDouble{
}, },
} }
var doublesValidateConfig = []testDouble{ var testHelperMethod = []testHelperMethodStruct{
testDouble{config: config.GitHubProvider{ testHelperMethodStruct{config: config.GitHubProvider{
Repo: "foo", Repo: "foo",
User: "bar", User: "bar",
}, },
valid: true, valid: true,
}, },
testDouble{config: config.GitHubProvider{ testHelperMethodStruct{config: config.GitHubProvider{
Repo: "", Repo: "",
User: "bar", User: "bar",
}, },
valid: false, valid: false,
}, },
testDouble{config: config.GitHubProvider{ testHelperMethodStruct{config: config.GitHubProvider{
Repo: "foo", Repo: "foo",
User: "", User: "",
}, },
@@ -73,8 +74,8 @@ var doublesValidateConfig = []testDouble{
var lastVersion, _ = semver.NewVersion("1.0.0") var lastVersion, _ = semver.NewVersion("1.0.0")
var newVersion, _ = semver.NewVersion("2.0.0") var newVersion, _ = semver.NewVersion("2.0.0")
var fourthsReleas = []testFourth{ var testReleases = []testReleaseStruct{
testFourth{ testReleaseStruct{
config: config.GitHubProvider{ config: config.GitHubProvider{
Repo: "foo", Repo: "foo",
User: "bar", User: "bar",
@@ -99,7 +100,7 @@ var fourthsReleas = []testFourth{
requestResponseCode: 200, requestResponseCode: 200,
valid: true, valid: true,
}, },
testFourth{ testReleaseStruct{
config: config.GitHubProvider{ config: config.GitHubProvider{
Repo: "foo", Repo: "foo",
User: "bar", User: "bar",
@@ -120,8 +121,7 @@ var fourthsReleas = []testFourth{
Title: "title", Title: "title",
Content: "content", Content: "content",
}, },
requestResponseBody: "", requestResponseCode: 400,
requestResponseCode: 422,
valid: false, valid: false,
}, },
} }
@@ -141,7 +141,7 @@ func initHTTPServer(respCode int, body string) *httptest.Server {
} }
func TestNew(t *testing.T) { func TestNew(t *testing.T) {
for _, testOject := range doublesNew { for _, testOject := range testNewClient {
if testOject.valid { if testOject.valid {
os.Setenv("GITHUB_ACCESS_TOKEN", "XXX") os.Setenv("GITHUB_ACCESS_TOKEN", "XXX")
} }
@@ -156,7 +156,7 @@ func TestNew(t *testing.T) {
func TestGetCommitURL(t *testing.T) { func TestGetCommitURL(t *testing.T) {
os.Setenv("GITHUB_ACCESS_TOKEN", "XX") os.Setenv("GITHUB_ACCESS_TOKEN", "XX")
for _, testOject := range doublesNew { for _, testOject := range testNewClient {
client, _ := github.New(&testOject.config) client, _ := github.New(&testOject.config)
actualUrl := client.GetCommitURL() actualUrl := client.GetCommitURL()
if testOject.config.CustomURL != "" { if testOject.config.CustomURL != "" {
@@ -174,7 +174,7 @@ func TestGetCommitURL(t *testing.T) {
func TestGetCompareURL(t *testing.T) { func TestGetCompareURL(t *testing.T) {
os.Setenv("GITHUB_ACCESS_TOKEN", "XX") os.Setenv("GITHUB_ACCESS_TOKEN", "XX")
for _, testOject := range doublesNew { for _, testOject := range testNewClient {
client, _ := github.New(&testOject.config) client, _ := github.New(&testOject.config)
actualUrl := client.GetCompareURL("1", "2") actualUrl := client.GetCompareURL("1", "2")
if testOject.config.CustomURL != "" { if testOject.config.CustomURL != "" {
@@ -192,7 +192,7 @@ func TestGetCompareURL(t *testing.T) {
func TestValidateConfig(t *testing.T) { func TestValidateConfig(t *testing.T) {
os.Setenv("GITHUB_ACCESS_TOKEN", "XX") os.Setenv("GITHUB_ACCESS_TOKEN", "XX")
for _, testOject := range doublesValidateConfig { for _, testOject := range testHelperMethod {
client, _ := github.New(&testOject.config) client, _ := github.New(&testOject.config)
err := client.ValidateConfig() err := client.ValidateConfig()
@@ -205,7 +205,7 @@ func TestValidateConfig(t *testing.T) {
func TestCreateRelease(t *testing.T) { func TestCreateRelease(t *testing.T) {
os.Setenv("GITHUB_ACCESS_TOKEN", "XX") os.Setenv("GITHUB_ACCESS_TOKEN", "XX")
for _, testObejct := range fourthsReleas { for _, testObejct := range testReleases {
if testObejct.valid { if testObejct.valid {
server := initHTTPServer(testObejct.requestResponseCode, testObejct.requestResponseBody) server := initHTTPServer(testObejct.requestResponseCode, testObejct.requestResponseBody)
testObejct.config.CustomURL = server.URL testObejct.config.CustomURL = server.URL