Skip to content

Commit

Permalink
Add test case for when base_url property of YAML is specified
Browse files Browse the repository at this point in the history
  • Loading branch information
tkak committed Aug 30, 2018
1 parent 371b36f commit 080bafe
Showing 1 changed file with 83 additions and 0 deletions.
83 changes: 83 additions & 0 deletions notifier/github/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,89 @@ func TestNewClient(t *testing.T) {
}
}

func TestNewClientWithBaseURL(t *testing.T) {
githubBaseURL := os.Getenv(EnvBaseURL)
defer func() {
os.Setenv(EnvBaseURL, githubBaseURL)
}()
os.Setenv(EnvBaseURL, "")

testCases := []struct {
config Config
envBaseURL string
expect string
}{
{
// specify directly
config: Config{
Token: "abcdefg",
BaseURL: "https://git.example.com/api/v3/",
},
envBaseURL: "",
expect: "https://git.example.com/api/v3/",
},
{
// specify via env but not to be set env (part 1)
config: Config{
Token: "abcdefg",
BaseURL: "GITHUB_BASE_URL",
},
envBaseURL: "",
expect: "https://api.github.com/",
},
{
// specify via env (part 1)
config: Config{
Token: "abcdefg",
BaseURL: "GITHUB_BASE_URL",
},
envBaseURL: "https://git.example.com/api/v3/",
expect: "https://git.example.com/api/v3/",
},
{
// specify via env but not to be set env (part 2)
config: Config{
Token: "abcdefg",
BaseURL: "$GITHUB_BASE_URL",
},
envBaseURL: "",
expect: "https://api.github.com/",
},
{
// specify via env (part 2)
config: Config{
Token: "abcdefg",
BaseURL: "$GITHUB_BASE_URL",
},
envBaseURL: "https://git.example.com/api/v3/",
expect: "https://git.example.com/api/v3/",
},
{
// no specification (part 1)
config: Config{Token: "abcdefg"},
envBaseURL: "",
expect: "https://api.github.com/",
},
{
// no specification (part 2)
config: Config{Token: "abcdefg"},
envBaseURL: "https://git.example.com/api/v3/",
expect: "https://api.github.com/",
},
}
for _, testCase := range testCases {
os.Setenv(EnvBaseURL, testCase.envBaseURL)
c, err := NewClient(testCase.config)
if err != nil {
continue
}
url := c.Client.BaseURL.String()
if url != testCase.expect {
t.Errorf("got %q but want %q", url, testCase.expect)
}
}
}

func TestIsNumber(t *testing.T) {
testCases := []struct {
pr PullRequest
Expand Down

0 comments on commit 080bafe

Please sign in to comment.