diff --git a/.github/workflows/pull_request.yml b/.github/workflows/pull_request.yml new file mode 100644 index 0000000..37019f0 --- /dev/null +++ b/.github/workflows/pull_request.yml @@ -0,0 +1,39 @@ +name: Pull Request +on: + pull_request: + branches: + - main +jobs: + test-and-lint: + name: Test, Format & Lint + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v6 + - name: Set up Go + uses: actions/setup-go@v6 + with: + go-version: "1.25" + cache: true + - name: Check formatting + run: | + # Fails if any files are not formatted correctly + if [ -n "$(gofmt -l .)" ]; then + echo "Go code is not formatted:" + gofmt -d . + exit 1 + fi + - name: Run go vet + run: go vet ./... + - name: Run linter + uses: golangci/golangci-lint-action@v9 + with: + version: latest + - name: Run tests + run: go test -v ./... -coverprofile=coverage.out + - name Generate coverage report + run: go tool cover -html=coverage.out -o coverage.html + - name: Upload test coverage + uses: actions/upload-artifact@v6 + with: + name: coverage.html diff --git a/client.go b/client.go index d43da08..3090307 100644 --- a/client.go +++ b/client.go @@ -143,7 +143,7 @@ func (c *Client) handleAPIError(resp *http.Response) error { // Returns: // - *http.Request: The prepared HTTP request // - error: An error if the context is nil or request creation fails -func (c *Client) newRequest(ctx context.Context, method, path string, body any) (*http.Request, error) { +func (c *Client) newRequest(ctx context.Context, method, path string, _ any) (*http.Request, error) { if ctx == nil { return nil, fmt.Errorf("context must not be nil") } diff --git a/ping_test.go b/ping_test.go index 38afc99..62ef142 100644 --- a/ping_test.go +++ b/ping_test.go @@ -14,7 +14,9 @@ func TestGet(t *testing.T) { w.WriteHeader(http.StatusOK) }) - err := client.Ping.Get(nil) + var nilContext context.Context = nil + + err := client.Ping.Get(nilContext) if err == nil { t.Errorf("Expected error for nil context, got nil") @@ -26,7 +28,7 @@ func TestGet(t *testing.T) { w.WriteHeader(http.StatusOK) }) - ctx, cancel := context.WithCancel(context.Background()) + ctx, cancel := context.WithCancel(t.Context()) cancel() @@ -44,7 +46,7 @@ func TestGet(t *testing.T) { onspring.WithHTTPClient(&http.Client{Transport: &ErrorTransport{}}), ) - err := client.Ping.Get(context.Background()) + err := client.Ping.Get(t.Context()) if err == nil { t.Errorf("Expected network error, got nil") @@ -62,7 +64,7 @@ func TestGet(t *testing.T) { onspring.WithHTTPClient(client.HTTPClient()), ) - err := invalidClient.Ping.Get(context.Background()) + err := invalidClient.Ping.Get(t.Context()) if err == nil { t.Errorf("Expected request creation error, got nil") @@ -82,7 +84,7 @@ func TestGet(t *testing.T) { w.WriteHeader(http.StatusOK) }) - err := client.Ping.Get(context.Background()) + err := client.Ping.Get(t.Context()) if err != nil { t.Errorf("Expected no error, got %v", err) @@ -94,7 +96,7 @@ func TestGet(t *testing.T) { w.WriteHeader(http.StatusInternalServerError) }) - err := client.Ping.Get(context.Background()) + err := client.Ping.Get(t.Context()) if err == nil { t.Errorf("Expected error, got nil")