Skip to content

Commit

Permalink
github: cleanup repository, hook and status tests
Browse files Browse the repository at this point in the history
  • Loading branch information
bradrydzewski committed Jul 6, 2018
1 parent d71894a commit 403c057
Show file tree
Hide file tree
Showing 19 changed files with 1,022 additions and 127 deletions.
8 changes: 0 additions & 8 deletions scm/driver/github/github.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
"bytes"
"context"
"encoding/json"
"io"
"net/url"
"strconv"
"strings"
Expand Down Expand Up @@ -109,13 +108,6 @@ func (c *wrapper) do(ctx context.Context, method, path string, in, out interface
return res, nil
}

// if raw output is expected, copy to the provided
// buffer and exit.
if w, ok := out.(io.Writer); ok {
io.Copy(w, res.Body)
return res, nil
}

// if a json response is expected, parse and return
// the json response.
return res, json.NewDecoder(res.Body).Decode(out)
Expand Down
40 changes: 40 additions & 0 deletions scm/driver/github/issue_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -255,3 +255,43 @@ func TestIssueClose(t *testing.T) {
t.Run("Request", testRequest(res))
t.Run("Rate", testRate(res))
}

func TestIssueLock(t *testing.T) {
defer gock.Off()

gock.New("https://api.github.com").
Put("/repos/octocat/hello-world/issues/1/lock").
Reply(204).
Type("application/json").
SetHeaders(mockHeaders)

client := NewDefault()
res, err := client.Issues.Lock(context.Background(), "octocat/hello-world", 1)
if err != nil {
t.Error(err)
return
}

t.Run("Request", testRequest(res))
t.Run("Rate", testRate(res))
}

func TestIssueUnlock(t *testing.T) {
defer gock.Off()

gock.New("https://api.github.com").
Delete("/repos/octocat/hello-world/issues/1/lock").
Reply(204).
Type("application/json").
SetHeaders(mockHeaders)

client := NewDefault()
res, err := client.Issues.Unlock(context.Background(), "octocat/hello-world", 1)
if err != nil {
t.Error(err)
return
}

t.Run("Request", testRequest(res))
t.Run("Rate", testRate(res))
}
Loading

0 comments on commit 403c057

Please sign in to comment.