Skip to content

Commit

Permalink
DE-1391 Enable more linters (#395)
Browse files Browse the repository at this point in the history
  • Loading branch information
vtopc authored Mar 1, 2025
1 parent d3e87f7 commit bcac90e
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 63 deletions.
9 changes: 4 additions & 5 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ linters:
- gocyclo
- noctx
- gomodguard
- unused
- nolintlint

# TODO:
# - stylecheck # TODO(v5): enable
# - unused
# - stylecheck # TODO(v6): enable

linters-settings:
gocritic:
Expand All @@ -33,10 +33,9 @@ linters-settings:
- performance
- style
disabled-checks:
- singleCaseSwitch
- hugeParam # TODO(v5): enable?
- singleCaseSwitch # redundant
- hugeParam # TODO(v6): allocations critical; enable?
- sprintfQuotedString # noisy # TODO: enable
- exitAfterDefer # TODO: enable?

errcheck:
# List of functions to exclude from checking, where each entry is a single function to exclude.
Expand Down
10 changes: 0 additions & 10 deletions acceptance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package mailgun
import (
"fmt"
"os"
"testing"
)

// Return the variable missing which caused the test to be skipped
Expand All @@ -15,12 +14,3 @@ func SkipNetworkTest() string {
}
return ""
}

func spendMoney(t *testing.T, tFunc func()) {
ok := os.Getenv("MG_SPEND_MONEY")
if ok != "" {
tFunc()
} else {
t.Log("Money spending not allowed, not running function.")
}
}
12 changes: 5 additions & 7 deletions events.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,13 +171,11 @@ func (ei *EventIterator) fetch(ctx context.Context, url string) error {

// EventPoller maintains the state necessary for polling events
type EventPoller struct {
it *EventIterator
opts ListEventOptions
thresholdTime time.Time
beginTime time.Time
sleepUntil time.Time
mg Mailgun
err error
it *EventIterator
opts ListEventOptions
beginTime time.Time
mg Mailgun
err error
}

// PollEvents polls the events api and return new events as they occur
Expand Down
15 changes: 10 additions & 5 deletions examples_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ func ExampleMailgunImpl_ValidateEmail() {

ev, err := mg.ValidateEmail(ctx, "joe@example.com", false)
if err != nil {
log.Fatal(err)
log.Println(err)
return
}
if ev.DidYouMean != "" {
log.Printf("The address is syntactically valid, but perhaps has a typo.")
Expand All @@ -43,7 +44,8 @@ func ExampleMailgunImpl_UpdateMailingList() {
Description: "Joe's status report list",
})
if err != nil {
log.Fatal(err)
log.Println(err)
return
}
}

Expand All @@ -66,7 +68,8 @@ func ExampleMailgunImpl_Send_constructed() {
m.SetHTML("<html><body><h1>Testing some Mailgun Awesomeness!!</h1></body></html>")
_, id, err := mg.Send(ctx, m)
if err != nil {
log.Fatal(err)
log.Println(err)
return
}
log.Printf("Message id=%s", id)
}
Expand All @@ -89,7 +92,8 @@ Testing some Mailgun MIME awesomeness!
m := mailgun.NewMIMEMessage("example.com", io.NopCloser(strings.NewReader(exampleMime)), "bargle.garf@example.com")
_, id, err := mg.Send(ctx, m)
if err != nil {
log.Fatal(err)
log.Println(err)
return
}
log.Printf("Message id=%s", id)
}
Expand All @@ -107,7 +111,8 @@ func ExampleMailgunImpl_ListRoutes() {
}
}
if it.Err() != nil {
log.Fatal(it.Err())
log.Println(it.Err())
return
}
}

Expand Down
1 change: 0 additions & 1 deletion mailgun.go
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,6 @@ type MailgunImpl struct {
apiKey string
webhookSigningKey string
client *http.Client
baseURL string
overrideHeaders map[string]string
}

Expand Down
3 changes: 3 additions & 0 deletions mailgun_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ var server *mocks.Server
func TestMain(m *testing.M) {
server = mocks.NewServer()
defer server.Stop()
// TODO: os.Exit will exit, and `defer server.Stop()` will not run
// switch to testify suite
//nolint:gocritic // ignored till switched to testify suite
os.Exit(m.Run())
}

Expand Down
35 changes: 0 additions & 35 deletions webhooks_test.go
Original file line number Diff line number Diff line change
@@ -1,16 +1,11 @@
package mailgun_test

import (
"bytes"
"context"
"crypto/hmac"
"crypto/sha256"
"encoding/hex"
"io"
"mime/multipart"
"net/http"
"net/url"
"strings"
"testing"

"github.com/mailgun/mailgun-go/v4"
Expand Down Expand Up @@ -102,36 +97,6 @@ func TestVerifyWebhookSignature(t *testing.T) {
}
}

func buildFormRequest(ctx context.Context, fields map[string]string) *http.Request {
values := url.Values{}

for k, v := range fields {
values.Add(k, v)
}

r := strings.NewReader(values.Encode())
req, _ := http.NewRequestWithContext(ctx, http.MethodPost, "/", r)
req.Header.Set("Content-Type", "application/x-www-form-urlencoded")

return req
}

func buildMultipartFormRequest(ctx context.Context, fields map[string]string) *http.Request {
buf := &bytes.Buffer{}
writer := multipart.NewWriter(buf)

for k, v := range fields {
_ = writer.WriteField(k, v)
}

writer.Close()

req, _ := http.NewRequestWithContext(ctx, http.MethodPost, "/", buf)
req.Header.Set("Content-type", writer.FormDataContentType())

return req
}

func getSignatureFields(key string, signed bool) map[string]string {
badSignature := hex.EncodeToString([]byte("badsignature"))

Expand Down

0 comments on commit bcac90e

Please sign in to comment.