Skip to content

Commit

Permalink
V-style logging with glog and check errs (ewilde#18)
Browse files Browse the repository at this point in the history
* Level logging with glog and check errs

* fix typo and linter and makefile

* address code review

* remove glog vendor dep
  • Loading branch information
cxuu authored and ewilde committed Nov 29, 2018
1 parent 0ce4c32 commit 80a0796
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 13 deletions.
10 changes: 5 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
SOURCEDIR=.
SOURCES = $(shell find $(SOURCEDIR) -name '*.go')
GOFMT_FILES?=$$(find . -name '*.go' |grep -v vendor)
VERSION=$(git describe --always --tags)
GOFMT_FILES?=$$(shell find . -name '*.go' | grep -v vendor)
VERSION=$(shell git describe --always --tags)
BINARY=bin/runscope

bin: $(BINARY)
Expand All @@ -11,9 +11,9 @@ $(BINARY): $(SOURCES)

build:
go get github.com/golang/lint/golint
go test $(go list ./... | grep -v /vendor/)
go vet $(go list ./... | grep -v /vendor/)
golint $(go list ./... | grep -v /vendor/)
go test $(shell go list ./... | grep -v /vendor/)
go vet $(shell go list ./... | grep -v /vendor/)
golint $(shell go list ./... | grep -v /vendor/)

fmt:
gofmt -w $(GOFMT_FILES)
Expand Down
3 changes: 2 additions & 1 deletion bucket.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,12 +110,13 @@ func (client *Client) ListBuckets() ([]*Bucket, error) {
return buckets, err
}

// ListTestsInput represents the input to ListTests func
type ListTestsInput struct {
BucketName string
Count int
}

// ListBuckets lists all buckets for an account
// ListTests lists all tests for a bucket
func (client *Client) ListTests(input *ListTestsInput) ([]*Test, error) {
count := input.Count
if count == 0 {
Expand Down
16 changes: 10 additions & 6 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ import (
"encoding/json"
"fmt"
"io"
"io/ioutil"
"net/http"
"net/url"

"github.com/hashicorp/go-cleanhttp"
"io/ioutil"
"strings"
"sync"

"github.com/hashicorp/go-cleanhttp"
)

// APIURL is the default runscope api uri
Expand Down Expand Up @@ -156,7 +156,10 @@ func (client *Client) readResource(resourceType string, resourceName string, end
}
defer resp.Body.Close()

bodyBytes, _ := ioutil.ReadAll(resp.Body)
bodyBytes, err := ioutil.ReadAll(resp.Body)
if err != nil {
return response, err
}
bodyString := string(bodyBytes)
DebugF(2, " response: %d %s", resp.StatusCode, bodyString)

Expand All @@ -166,12 +169,13 @@ func (client *Client) readResource(resourceType string, resourceName string, end
return response, fmt.Errorf("Status: %s Error reading %s: %s",
resp.Status, resourceType, resourceName)
}

return response, fmt.Errorf("Status: %s Error reading %s: %s, reason: %q",
resp.Status, resourceType, resourceName, errorResp.ErrorMessage)
}

json.Unmarshal(bodyBytes, &response)
if err = json.Unmarshal(bodyBytes, &response); err != nil {
return response, fmt.Errorf("failed to Unmarshal response body: %v", err)
}
return response, nil
}

Expand Down
2 changes: 1 addition & 1 deletion client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ func clientConfigure() *Client {
func testPreCheck(t *testing.T) {
skip := os.Getenv("RUNSCOPE_ACC") == ""
if skip {
t.Log("runscope client.go tests require setting RUNSCOPE")
t.Log("runscope client.go tests require setting RUNSCOPE_ACC")
t.Skip()
}

Expand Down

0 comments on commit 80a0796

Please sign in to comment.