-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
719 additions
and
69 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
name: 'Tests & Code coverage' | ||
|
||
on: | ||
push: | ||
branches: | ||
- master | ||
|
||
jobs: | ||
tests: | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- uses: actions/setup-go@v4 | ||
with: | ||
go-version: "1.20" | ||
|
||
- uses: actions/checkout@v4 | ||
|
||
- name: Install dependencies | ||
run: go mod download | ||
|
||
- name: Run test and converage | ||
run: go test ./... -v -coverprofile=coverage.out -covermode=atomic | ||
|
||
- name: Upload coverage to Codecov | ||
uses: codecov/codecov-action@v3 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
package choruspro | ||
|
||
import ( | ||
"fmt" | ||
"net/http" | ||
"net/http/httptest" | ||
"testing" | ||
) | ||
|
||
func setup() (client *Client, mux *http.ServeMux, teardown func()) { | ||
mux = http.NewServeMux() | ||
|
||
// OAuth token | ||
mux.HandleFunc("/api/oauth/token", func(w http.ResponseWriter, r *http.Request) { | ||
w.WriteHeader(http.StatusOK) | ||
fmt.Fprint(w, `{"access_token":"token","token_type":"Bearer","expires_in":3600}`) | ||
}) | ||
|
||
server := httptest.NewServer(mux) | ||
|
||
client = NewClient() | ||
url, _ := client.BaseUrl.Parse(server.URL + "/") | ||
client.BaseUrl = url | ||
client.AuthUrl = url | ||
|
||
return client, mux, server.Close | ||
} | ||
|
||
// Test function under s.client.DoRequest failure. | ||
// Method f should be a regular call that would normally succeed, but | ||
// should return an error when NewRequest or s.client.DoRequest fails. | ||
func testDoRequestFailure(t *testing.T, methodName string, client *Client, f func() error) { | ||
t.Helper() | ||
if methodName == "" { | ||
t.Error("testNewRequestAndDoFailure : method name should be provided") | ||
} | ||
|
||
client.BaseUrl.Path = "" | ||
err := f() | ||
|
||
if err == nil { | ||
t.Errorf("client.BaseURL.Path='' %v err = nil, want error", methodName) | ||
} | ||
} | ||
|
||
func testMethod(t *testing.T, r *http.Request, want string) { | ||
t.Helper() | ||
if got := r.Method; got != want { | ||
t.Errorf("Request method : %v, got %v", got, want) | ||
} | ||
} | ||
|
||
func assertNilError(t *testing.T, err error) { | ||
t.Helper() | ||
if err != nil { | ||
t.Errorf("unexpected error: %v", err) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.