Skip to content

Commit

Permalink
errcheck
Browse files Browse the repository at this point in the history
  • Loading branch information
vtopc committed Nov 18, 2024
1 parent 790a589 commit f7e20d7
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 14 deletions.
6 changes: 5 additions & 1 deletion common_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,11 @@ import (
func randomString(n int, prefix string) string {
const alphanum = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"
var bytes = make([]byte, n)
rand.Read(bytes)
_, err := rand.Read(bytes)
if err != nil {
panic(fmt.Sprintf("rand.Read: %v", err))
}

for i, b := range bytes {
bytes[i] = alphanum[b%byte(len(alphanum))]
}
Expand Down
3 changes: 2 additions & 1 deletion mailgun_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ func TestValidBaseAPI(t *testing.T) {
b, err := json.Marshal(resp)
require.NoError(t, err)

w.Write(b)
_, err = w.Write(b)
require.NoError(t, err)
}))

apiBases := []string{
Expand Down
27 changes: 18 additions & 9 deletions messages_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,8 @@ func TestSendMGSTO(t *testing.T) {

ctx := context.Background()
m := mailgun.NewMessage(fromUser, exampleSubject, exampleText, toUser)
m.SetSTOPeriod("24h")
err = m.SetSTOPeriod("24h")
require.NoError(t, err)
msg, id, err := mg.Send(ctx, m)
require.NoError(t, err)
t.Log("TestSendMGSTO:MSG(" + msg + "),ID(" + id + ")")
Expand Down Expand Up @@ -218,9 +219,12 @@ func TestSendMGTag(t *testing.T) {

ctx := context.Background()
m := mailgun.NewMessage(fromUser, exampleSubject, exampleText+"Tags Galore!\n", toUser)
m.AddTag("FooTag")
m.AddTag("BarTag")
m.AddTag("BlortTag")
err = m.AddTag("FooTag")
require.NoError(t, err)
err = m.AddTag("BarTag")
require.NoError(t, err)
err = m.AddTag("BlortTag")
require.NoError(t, err)
msg, id, err := mg.Send(ctx, m)
require.NoError(t, err)
t.Log("TestSendTag:MSG(" + msg + "),ID(" + id + ")")
Expand Down Expand Up @@ -255,7 +259,8 @@ func TestSendMGBatchFailRecipients(t *testing.T) {

m := mailgun.NewMessage(fromUser, exampleSubject, exampleText+"Batch\n")
for i := 0; i < mailgun.MaxNumberOfRecipients; i++ {
m.AddRecipient("") // We expect this to indicate a failure at the API
err := m.AddRecipient("") // We expect this to indicate a failure at the API
require.NoError(t, err)
}
err := m.AddRecipientAndVariables(toUser, nil)
// In case of error the SDK didn't send the message,
Expand Down Expand Up @@ -397,10 +402,14 @@ func TestSendMGMessageVariables(t *testing.T) {
mg.SetAPIBase(srv.URL + "/v3")

m := mailgun.NewMessage(fromUser, exampleSubject, exampleText, toUser)
m.AddVariable(exampleStrVarKey, exampleStrVarVal)
m.AddVariable(exampleBoolVarKey, false)
m.AddVariable(exampleMapVarKey, exampleMapVarVal)
m.AddTemplateVariable("templateVariable", exampleTemplateVariable)
err := m.AddVariable(exampleStrVarKey, exampleStrVarVal)
require.NoError(t, err)
err = m.AddVariable(exampleBoolVarKey, false)
require.NoError(t, err)
err = m.AddVariable(exampleMapVarKey, exampleMapVarVal)
require.NoError(t, err)
err = m.AddTemplateVariable("templateVariable", exampleTemplateVariable)
require.NoError(t, err)

msg, id, err := mg.Send(context.Background(), m)
require.NoError(t, err)
Expand Down
6 changes: 3 additions & 3 deletions webhooks_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ func buildMultipartFormRequest(fields map[string]string) *http.Request {
writer := multipart.NewWriter(buf)

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

writer.Close()
Expand All @@ -171,8 +171,8 @@ func getSignatureFields(key string, signed bool) map[string]string {

if signed {
h := hmac.New(sha256.New, []byte(key))
io.WriteString(h, fields["timestamp"])
io.WriteString(h, fields["token"])
_, _ = io.WriteString(h, fields["timestamp"])
_, _ = io.WriteString(h, fields["token"])
hash := h.Sum(nil)

fields["signature"] = hex.EncodeToString(hash)
Expand Down

0 comments on commit f7e20d7

Please sign in to comment.