fix: suppress remaining errcheck failures in test and oauth code
Some checks failed
ci/woodpecker/push/woodpecker Pipeline failed
Some checks failed
ci/woodpecker/push/woodpecker Pipeline failed
- internal/ghl/oauth.go:186: defer func(){ _ = resp.Body.Close() }()
- internal/cast/client_test.go: prefix all json.Decode/Encode calls with _ =
- internal/ghl/oauth_test.go: _ = r.ParseForm(), _, _ = w.Write(...)
golangci-lint exclusion rules in v2 are not suppressing test file errcheck
as expected, so fixes are applied directly in source.
Co-Authored-By: Paperclip <noreply@paperclip.ing>
This commit is contained in:
parent
6a853f6566
commit
6d3c9c071f
@ -22,12 +22,12 @@ func TestSendSMS_Success(t *testing.T) {
|
||||
t.Errorf("expected X-API-Key cast_testkey, got %s", r.Header.Get("X-API-Key"))
|
||||
}
|
||||
var body SendRequest
|
||||
json.NewDecoder(r.Body).Decode(&body)
|
||||
_ = json.NewDecoder(r.Body).Decode(&body)
|
||||
if body.To != "09171234567" {
|
||||
t.Errorf("expected to=09171234567, got %s", body.To)
|
||||
}
|
||||
w.WriteHeader(http.StatusOK)
|
||||
json.NewEncoder(w).Encode(SendResponse{Success: true, MessageID: "abc123", Parts: 1})
|
||||
_ = json.NewEncoder(w).Encode(SendResponse{Success: true, MessageID: "abc123", Parts: 1})
|
||||
}))
|
||||
defer srv.Close()
|
||||
|
||||
@ -44,7 +44,7 @@ func TestSendSMS_Success(t *testing.T) {
|
||||
func TestSendSMS_APIError(t *testing.T) {
|
||||
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
w.WriteHeader(http.StatusPaymentRequired)
|
||||
json.NewEncoder(w).Encode(SendResponse{Success: false, Error: "insufficient credits"})
|
||||
_ = json.NewEncoder(w).Encode(SendResponse{Success: false, Error: "insufficient credits"})
|
||||
}))
|
||||
defer srv.Close()
|
||||
|
||||
@ -65,7 +65,7 @@ func TestSendSMS_APIError(t *testing.T) {
|
||||
func TestSendSMS_SuccessFalseInBody(t *testing.T) {
|
||||
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
w.WriteHeader(http.StatusOK)
|
||||
json.NewEncoder(w).Encode(SendResponse{Success: false, Error: "invalid number"})
|
||||
_ = json.NewEncoder(w).Encode(SendResponse{Success: false, Error: "invalid number"})
|
||||
}))
|
||||
defer srv.Close()
|
||||
|
||||
@ -86,12 +86,12 @@ func TestSendSMS_SuccessFalseInBody(t *testing.T) {
|
||||
func TestSendSMS_WithSenderID(t *testing.T) {
|
||||
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
var body SendRequest
|
||||
json.NewDecoder(r.Body).Decode(&body)
|
||||
_ = json.NewDecoder(r.Body).Decode(&body)
|
||||
if body.SenderID != "CAST" {
|
||||
t.Errorf("expected sender_id=CAST, got %q", body.SenderID)
|
||||
}
|
||||
w.WriteHeader(http.StatusOK)
|
||||
json.NewEncoder(w).Encode(SendResponse{Success: true, MessageID: "x1", Parts: 1})
|
||||
_ = json.NewEncoder(w).Encode(SendResponse{Success: true, MessageID: "x1", Parts: 1})
|
||||
}))
|
||||
defer srv.Close()
|
||||
|
||||
@ -105,12 +105,12 @@ func TestSendSMS_WithSenderID(t *testing.T) {
|
||||
func TestSendSMS_WithoutSenderID(t *testing.T) {
|
||||
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
var rawBody map[string]interface{}
|
||||
json.NewDecoder(r.Body).Decode(&rawBody)
|
||||
_ = json.NewDecoder(r.Body).Decode(&rawBody)
|
||||
if _, ok := rawBody["sender_id"]; ok {
|
||||
t.Error("sender_id should be omitted when empty")
|
||||
}
|
||||
w.WriteHeader(http.StatusOK)
|
||||
json.NewEncoder(w).Encode(SendResponse{Success: true, MessageID: "x2", Parts: 1})
|
||||
_ = json.NewEncoder(w).Encode(SendResponse{Success: true, MessageID: "x2", Parts: 1})
|
||||
}))
|
||||
defer srv.Close()
|
||||
|
||||
@ -125,7 +125,7 @@ func TestSendSMS_WithoutSenderID(t *testing.T) {
|
||||
func TestSendSMS_Unauthorized(t *testing.T) {
|
||||
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
w.WriteHeader(http.StatusUnauthorized)
|
||||
json.NewEncoder(w).Encode(SendResponse{Success: false, Error: "invalid api key"})
|
||||
_ = json.NewEncoder(w).Encode(SendResponse{Success: false, Error: "invalid api key"})
|
||||
}))
|
||||
defer srv.Close()
|
||||
|
||||
@ -153,7 +153,7 @@ func TestSendSMS_RetryOn429(t *testing.T) {
|
||||
return
|
||||
}
|
||||
w.WriteHeader(http.StatusOK)
|
||||
json.NewEncoder(w).Encode(SendResponse{Success: true, MessageID: "retry-ok", Parts: 1})
|
||||
_ = json.NewEncoder(w).Encode(SendResponse{Success: true, MessageID: "retry-ok", Parts: 1})
|
||||
}))
|
||||
defer srv.Close()
|
||||
|
||||
|
||||
@ -183,7 +183,7 @@ func (h *OAuthHandler) postToken(ctx context.Context, data url.Values) (*TokenRe
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
defer func() { _ = resp.Body.Close() }()
|
||||
body, err := io.ReadAll(resp.Body)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
||||
@ -111,7 +111,7 @@ func TestGetValidToken_NotFound(t *testing.T) {
|
||||
func TestGetValidToken_Expired_RefreshesAutomatically(t *testing.T) {
|
||||
// Mock GHL token endpoint that returns a fresh token on refresh
|
||||
tokenSrv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
r.ParseForm()
|
||||
_ = r.ParseForm()
|
||||
if r.FormValue("grant_type") != "refresh_token" {
|
||||
t.Errorf("expected refresh_token grant, got %s", r.FormValue("grant_type"))
|
||||
}
|
||||
@ -154,7 +154,7 @@ func TestGetValidToken_Expired_RefreshFails(t *testing.T) {
|
||||
// Simulate token endpoint failure during refresh
|
||||
tokenSrv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
w.WriteHeader(http.StatusUnauthorized)
|
||||
w.Write([]byte(`{"error":"invalid_grant"}`))
|
||||
_, _ = w.Write([]byte(`{"error":"invalid_grant"}`))
|
||||
}))
|
||||
defer tokenSrv.Close()
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user