Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

app-mapper: govet, golint, errcheck fixes #83

Merged
merged 2 commits into from
Aug 14, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion app-mapper/app_provisioner.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"errors"
"time"

"github.com/Sirupsen/logrus"
docker "github.com/fsouza/go-dockerclient"
)

Expand Down Expand Up @@ -62,7 +63,9 @@ func (p *dockerProvisioner) runApp(appID string) (hostname string, err error) {
}
defer func() {
if err != nil {
p.destroyApp(appID)
if err := p.destroyApp(appID); err != nil {
logrus.Warnf("docker provisioner: destroy app %q: %v", appID, err)
}
}
}()

Expand Down
3 changes: 2 additions & 1 deletion app-mapper/authenticator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,8 @@ func TestBadServerResponse(t *testing.T) {

shFunc := func(w http.ResponseWriter, r *http.Request, orgName string) {
w.WriteHeader(http.StatusOK)
w.Write(responseBody)
_, err := w.Write(responseBody)
assert.NoError(t, err, "Couldn't write response body")
}

testFunc := func(a authenticator) {
Expand Down
4 changes: 3 additions & 1 deletion app-mapper/organization_mapper.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,9 @@ func (m *dbMapper) runTransaction(runner func(*sqlx.Tx) error) error {
}

if err = runner(tx); err != nil {
tx.Rollback()
if err2 := tx.Rollback(); err2 != nil {
logrus.Warnf("organization mapper: transaction rollback: %v", err2)
}
return err
}

Expand Down
4 changes: 3 additions & 1 deletion app-mapper/proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,9 @@ func proxyWS(targetHost string, w http.ResponseWriter, r *http.Request) {
var wg sync.WaitGroup
cp := func(dst io.Writer, src io.Reader, tag string) {
defer wg.Done()
io.Copy(dst, src)
if _, err := io.Copy(dst, src); err != nil {
logrus.Debugf("proxy: websocket: %q io.Copy: %v", tag, err) // EOF is normal
}
logrus.Debugf("proxy: websocket: %q copier exited", tag)
}
wg.Add(2)
Expand Down
10 changes: 5 additions & 5 deletions app-mapper/proxy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,11 @@ func testHTTPRequest(t *testing.T, req *http.Request) {
// caches clients, and doesn't explicitly close them)
w.Header().Set("Connection", "close")
w.WriteHeader(http.StatusOK)
w.Write(targetResponse)
_, err := w.Write(targetResponse)
assert.NoError(t, err, "Couldn't write response body")
})

var recordedOrgName string
authenticator := authenticatorFunc(func(r *http.Request, orgName string) (authenticatorResponse, error) {
recordedOrgName = orgName
return authenticatorResponse{"somePersistentInternalID"}, nil
})

Expand Down Expand Up @@ -300,7 +299,8 @@ func TestUnauthorized(t *testing.T) {
func TestProxyWebSocket(t *testing.T) {
// Use a websocket echo server in the target
targetHandler := websocket.Handler(func(ws *websocket.Conn) {
io.Copy(ws, ws)
_, err := io.Copy(ws, ws)
assert.NoError(t, err, "Target handler copy failed")
})

testFunc := func(proxyHost string) {
Expand All @@ -315,7 +315,7 @@ func TestProxyWebSocket(t *testing.T) {
for i := 0; i < 100; i++ {
err = websocket.Message.Send(ws, messageToSend)
require.NoError(t, err, "Error sending message")
websocket.Message.Receive(ws, &messageToReceive)
err = websocket.Message.Receive(ws, &messageToReceive)

This comment was marked as abuse.

require.NoError(t, err, "Error receiving message")
require.Equal(t, messageToSend, messageToReceive)
messageToReceive = ""
Expand Down