Skip to content

Commit

Permalink
Fix lints
Browse files Browse the repository at this point in the history
  • Loading branch information
Jaime Piña committed Sep 11, 2019
1 parent 14fee71 commit 5eb297e
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 20 deletions.
5 changes: 2 additions & 3 deletions service/telegram/telegram.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"bytes"
"encoding/json"
"errors"
"fmt"
"net/http"
)

Expand Down Expand Up @@ -45,7 +46,7 @@ func (n *Notification) Send() error {
return errors.New("missing token")
}

url := API + "/bot" + n.Token + "/sendMessage"
url := fmt.Sprintf("%s/bot%s/sendMessage", API, n.Token)

payload := new(bytes.Buffer)
if err := json.NewEncoder(payload).Encode(n); err != nil {
Expand All @@ -56,11 +57,9 @@ func (n *Notification) Send() error {
if err != nil {
return err
}

defer resp.Body.Close()

var r apiResponse

if err := json.NewDecoder(resp.Body).Decode(&r); err != nil {
return err
}
Expand Down
18 changes: 10 additions & 8 deletions service/telegram/telegram_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,10 @@ func TestTelegramSend(t *testing.T) {
ts := httptest.NewServer(http.HandlerFunc(func(rw http.ResponseWriter, r *http.Request) {
hitServer = true

decoder := json.NewDecoder(r.Body)

var n Notification

_ = decoder.Decode(&n)
if err := json.NewDecoder(r.Body).Decode(&n); err != nil {
t.Error(err)
}

if r.Method != "POST" {
t.Error("HTTP method should be POST.")
Expand All @@ -40,14 +39,16 @@ func TestTelegramSend(t *testing.T) {
t.Error("missing message")
}

_ = json.NewEncoder(rw).Encode(mockResp)
if err := json.NewEncoder(rw).Encode(mockResp); err != nil {
t.Error(err)
}
}))

defer ts.Close()

API = ts.URL

mockResp.OK = true // successful
// successful
mockResp.OK = true
if err := n.Send(); err != nil {
t.Error(err)
}
Expand All @@ -56,7 +57,8 @@ func TestTelegramSend(t *testing.T) {
t.Error("didn't reach server")
}

mockResp.OK = false // failure
// failure
mockResp.OK = false
if err := n.Send(); err == nil {
t.Error("unexpected success")
}
Expand Down
7 changes: 1 addition & 6 deletions service/zulip/zulip.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,6 @@ import (
"strings"
)

var (
// API is the Pushbullet API endpoint.

)

type apiResponse struct {
ID int `json:"id"`
Code string `json:"code"`
Expand All @@ -35,7 +30,7 @@ type Notification struct {

// Send sends a Pushbullet notification.
func (n *Notification) Send() error {
data := url.Values{}
data := make(url.Values)
data.Set("type", n.Type)
if n.Type != "stream" && n.Type != "private" {
return fmt.Errorf("%s != stream || private", n.Type)
Expand Down
9 changes: 6 additions & 3 deletions service/zulip/zulip_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,12 @@ func TestSend(t *testing.T) {
t.Error("missing payload")
}

json.NewEncoder(rw).Encode(mockResponse)
if err := json.NewEncoder(rw).Encode(mockResponse); err != nil {
t.Error(err)
}
}))
defer ts.Close()

n.Endpoint = ts.URL
mockResponse.Result = "success"
if err := n.Send(); err != nil {
Expand All @@ -72,13 +75,13 @@ func TestSend(t *testing.T) {
t.Error(err)
}

mockResponse.Result = "error" // failure
// failure
mockResponse.Result = "error"
if err := n.Send(); err == nil {
t.Error("unexpected success")
}
n.Type = "dummy"
if err := n.Send(); err == nil {
t.Error("unexpected success")
}

}

0 comments on commit 5eb297e

Please sign in to comment.