Skip to content

Commit

Permalink
chore(http): make test diffs more readable (#2203)
Browse files Browse the repository at this point in the history
* chore(http): make test diffs more readable

* fixes

* add back telegraf output spacing

* whitespace hell

* jsonEqual2 -> jsonEqual
  • Loading branch information
imogenkinsman authored Jan 3, 2019
1 parent 36d6028 commit 7562c9a
Show file tree
Hide file tree
Showing 11 changed files with 83 additions and 95 deletions.
7 changes: 4 additions & 3 deletions http/api_handler_test.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
package http

import (
"go.uber.org/zap"
"io/ioutil"
"net/http"
"net/http/httptest"
"testing"

"go.uber.org/zap"
)

func TestAPIHandler_NotFound(t *testing.T) {
Expand Down Expand Up @@ -64,8 +65,8 @@ func TestAPIHandler_NotFound(t *testing.T) {
if tt.wants.contentType != "" && content != tt.wants.contentType {
t.Errorf("%q. get %v, want %v", tt.name, content, tt.wants.contentType)
}
if eq, _ := jsonEqual(string(body), tt.wants.body); tt.wants.body != "" && !eq {
t.Errorf("%q. get\n***%v***\n,\nwant\n***%v***", tt.name, string(body), tt.wants.body)
if eq, diff, _ := jsonEqual(string(body), tt.wants.body); tt.wants.body != "" && !eq {
t.Errorf("%q. -got/+want%s", tt.name, diff)
}

})
Expand Down
8 changes: 4 additions & 4 deletions http/auth_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ func TestService_handleGetAuthorizations(t *testing.T) {
if tt.wants.contentType != "" && content != tt.wants.contentType {
t.Errorf("%q. handleGetAuthorizations() = %v, want %v", tt.name, content, tt.wants.contentType)
}
if eq, diff, _ := jsonEqual2(string(body), tt.wants.body); tt.wants.body != "" && !eq {
if eq, diff, _ := jsonEqual(string(body), tt.wants.body); tt.wants.body != "" && !eq {
t.Errorf("%q. handleGetAuthorizations() = -got/+want %s", tt.name, diff)
}

Expand Down Expand Up @@ -347,7 +347,7 @@ func TestService_handleGetAuthorization(t *testing.T) {
if tt.wants.contentType != "" && content != tt.wants.contentType {
t.Errorf("%q. handleGetAuthorization() = %v, want %v", tt.name, content, tt.wants.contentType)
}
if eq, diff, err := jsonEqual2(string(body), tt.wants.body); err != nil || (tt.wants.body != "" && !eq) {
if eq, diff, err := jsonEqual(string(body), tt.wants.body); err != nil || (tt.wants.body != "" && !eq) {
t.Errorf("%q. handleGetAuthorization() = -got/+want %s**", tt.name, diff)
}
})
Expand Down Expand Up @@ -485,7 +485,7 @@ func TestService_handlePostAuthorization(t *testing.T) {
if tt.wants.contentType != "" && content != tt.wants.contentType {
t.Errorf("%q. handlePostAuthorization() = %v, want %v", tt.name, content, tt.wants.contentType)
}
if eq, diff, _ := jsonEqual2(string(body), tt.wants.body); tt.wants.body != "" && !eq {
if eq, diff, _ := jsonEqual(string(body), tt.wants.body); tt.wants.body != "" && !eq {
t.Errorf("%q. handlePostAuthorization() = -got/+want%s", tt.name, diff)
}
})
Expand Down Expand Up @@ -593,7 +593,7 @@ func TestService_handleDeleteAuthorization(t *testing.T) {
t.Errorf("%q. handleDeleteAuthorization() = %v, want %v", tt.name, content, tt.wants.contentType)
}

if eq, diff, _ := jsonEqual2(string(body), tt.wants.body); !eq {
if eq, diff, _ := jsonEqual(string(body), tt.wants.body); !eq {
t.Errorf("%q. handleDeleteAuthorization() = ***%s***", tt.name, diff)
}
})
Expand Down
28 changes: 14 additions & 14 deletions http/bucket_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,8 +161,8 @@ func TestService_handleGetBuckets(t *testing.T) {
if tt.wants.contentType != "" && content != tt.wants.contentType {
t.Errorf("%q. handleGetBuckets() = %v, want %v", tt.name, content, tt.wants.contentType)
}
if eq, _ := jsonEqual(string(body), tt.wants.body); tt.wants.body != "" && !eq {
t.Errorf("%q. handleGetBuckets() = \n***%v***\n,\nwant\n***%v***", tt.name, string(body), tt.wants.body)
if eq, diff, _ := jsonEqual(string(body), tt.wants.body); tt.wants.body != "" && !eq {
t.Errorf("%q. handleGetBuckets() = ***%s***", tt.name, diff)
}
})
}
Expand Down Expand Up @@ -282,8 +282,8 @@ func TestService_handleGetBucket(t *testing.T) {
if tt.wants.contentType != "" && content != tt.wants.contentType {
t.Errorf("%q. handleGetBucket() = %v, want %v", tt.name, content, tt.wants.contentType)
}
if eq, _ := jsonEqual(string(body), tt.wants.body); tt.wants.body != "" && !eq {
t.Errorf("%q. handleGetBucket() = \n***%v***\n,\nwant\n***%v***", tt.name, string(body), tt.wants.body)
if eq, diff, _ := jsonEqual(string(body), tt.wants.body); tt.wants.body != "" && !eq {
t.Errorf("%q. handleGetBucket() = ***%s***", tt.name, diff)
}
})
}
Expand Down Expand Up @@ -373,8 +373,8 @@ func TestService_handlePostBucket(t *testing.T) {
if tt.wants.contentType != "" && content != tt.wants.contentType {
t.Errorf("%q. handlePostBucket() = %v, want %v", tt.name, content, tt.wants.contentType)
}
if eq, _ := jsonEqual(string(body), tt.wants.body); tt.wants.body != "" && !eq {
t.Errorf("%q. handlePostBucket() = \n***%v***\n,\nwant\n***%v***", tt.name, string(body), tt.wants.body)
if eq, diff, _ := jsonEqual(string(body), tt.wants.body); tt.wants.body != "" && !eq {
t.Errorf("%q. handlePostBucket() = ***%s***", tt.name, diff)
}
})
}
Expand Down Expand Up @@ -474,8 +474,8 @@ func TestService_handleDeleteBucket(t *testing.T) {
if tt.wants.contentType != "" && content != tt.wants.contentType {
t.Errorf("%q. handleDeleteBucket() = %v, want %v", tt.name, content, tt.wants.contentType)
}
if eq, _ := jsonEqual(string(body), tt.wants.body); tt.wants.body != "" && !eq {
t.Errorf("%q. handleDeleteBucket() = \n***%v***\n,\nwant\n***%v***", tt.name, string(body), tt.wants.body)
if eq, diff, _ := jsonEqual(string(body), tt.wants.body); tt.wants.body != "" && !eq {
t.Errorf("%q. handleDeleteBucket() = ***%s***", tt.name, diff)
}
})
}
Expand Down Expand Up @@ -764,8 +764,8 @@ func TestService_handlePatchBucket(t *testing.T) {
if tt.wants.contentType != "" && content != tt.wants.contentType {
t.Errorf("%q. handlePatchBucket() = %v, want %v", tt.name, content, tt.wants.contentType)
}
if eq, _ := jsonEqual(string(body), tt.wants.body); tt.wants.body != "" && !eq {
t.Errorf("%q. handlePatchBucket() = \n***%v***\n,\nwant\n***%v***", tt.name, string(body), tt.wants.body)
if eq, diff, _ := jsonEqual(string(body), tt.wants.body); tt.wants.body != "" && !eq {
t.Errorf("%q. handlePatchBucket() = ***%s***", tt.name, diff)
}
})
}
Expand Down Expand Up @@ -852,8 +852,8 @@ func TestService_handlePostBucketMember(t *testing.T) {
if tt.wants.contentType != "" && content != tt.wants.contentType {
t.Errorf("%q. handlePostBucketMember() = %v, want %v", tt.name, content, tt.wants.contentType)
}
if eq, _ := jsonEqual(string(body), tt.wants.body); tt.wants.body != "" && !eq {
t.Errorf("%q. handlePostBucketMember() = \n***%v***\n,\nwant\n***%v***", tt.name, string(body), tt.wants.body)
if eq, diff, _ := jsonEqual(string(body), tt.wants.body); tt.wants.body != "" && !eq {
t.Errorf("%q. handlePostBucketMember() = ***%s***", tt.name, diff)
}
})
}
Expand Down Expand Up @@ -940,8 +940,8 @@ func TestService_handlePostBucketOwner(t *testing.T) {
if tt.wants.contentType != "" && content != tt.wants.contentType {
t.Errorf("%q. handlePostBucketOwner() = %v, want %v", tt.name, content, tt.wants.contentType)
}
if eq, _ := jsonEqual(string(body), tt.wants.body); tt.wants.body != "" && !eq {
t.Errorf("%q. handlePostBucketOwner() = \n***%v***\n,\nwant\n***%v***", tt.name, string(body), tt.wants.body)
if eq, diff, _ := jsonEqual(string(body), tt.wants.body); tt.wants.body != "" && !eq {
t.Errorf("%q. handlePostBucketOwner() = ***%s***", tt.name, diff)
}
})
}
Expand Down
32 changes: 16 additions & 16 deletions http/dashboard_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -228,8 +228,8 @@ func TestService_handleGetDashboards(t *testing.T) {
if tt.wants.contentType != "" && content != tt.wants.contentType {
t.Errorf("%q. handleGetDashboards() = %v, want %v", tt.name, content, tt.wants.contentType)
}
if eq, _ := jsonEqual(string(body), tt.wants.body); tt.wants.body != "" && !eq {
t.Errorf("%q. handleGetDashboards() = \n***%v***\n,\nwant\n***%v***", tt.name, string(body), tt.wants.body)
if eq, diff, _ := jsonEqual(string(body), tt.wants.body); tt.wants.body != "" && !eq {
t.Errorf("%q. handleGetDashboards() = ***%s***", tt.name, diff)
}

})
Expand Down Expand Up @@ -380,8 +380,8 @@ func TestService_handleGetDashboard(t *testing.T) {
if tt.wants.contentType != "" && content != tt.wants.contentType {
t.Errorf("%q. handleGetDashboard() = %v, want %v", tt.name, content, tt.wants.contentType)
}
if eq, _ := jsonEqual(string(body), tt.wants.body); tt.wants.body != "" && !eq {
t.Errorf("%q. handleGetDashboard() = \n***%v***\n,\nwant\n***%v***", tt.name, string(body), tt.wants.body)
if eq, diff, _ := jsonEqual(string(body), tt.wants.body); tt.wants.body != "" && !eq {
t.Errorf("%q. handleGetDashboard() = ***%s***", tt.name, diff)
}
})
}
Expand Down Expand Up @@ -504,8 +504,8 @@ func TestService_handlePostDashboard(t *testing.T) {
if tt.wants.contentType != "" && content != tt.wants.contentType {
t.Errorf("%q. handlePostDashboard() = %v, want %v", tt.name, content, tt.wants.contentType)
}
if eq, _ := jsonEqual(string(body), tt.wants.body); tt.wants.body != "" && !eq {
t.Errorf("%q. handlePostDashboard() = \n***%v***\n,\nwant\n***%v***", tt.name, string(body), tt.wants.body)
if eq, diff, _ := jsonEqual(string(body), tt.wants.body); tt.wants.body != "" && !eq {
t.Errorf("%q. handlePostDashboard() = ***%s***", tt.name, diff)
}
})
}
Expand Down Expand Up @@ -605,8 +605,8 @@ func TestService_handleDeleteDashboard(t *testing.T) {
if tt.wants.contentType != "" && content != tt.wants.contentType {
t.Errorf("%q. handleDeleteDashboard() = %v, want %v", tt.name, content, tt.wants.contentType)
}
if eq, _ := jsonEqual(string(body), tt.wants.body); tt.wants.body != "" && !eq {
t.Errorf("%q. handleDeleteDashboard() = \n***%v***\n,\nwant\n***%v***", tt.name, string(body), tt.wants.body)
if eq, diff, _ := jsonEqual(string(body), tt.wants.body); tt.wants.body != "" && !eq {
t.Errorf("%q. handleDeleteDashboard() = ***%s***", tt.name, diff)
}
})
}
Expand Down Expand Up @@ -791,8 +791,8 @@ func TestService_handlePatchDashboard(t *testing.T) {
if tt.wants.contentType != "" && content != tt.wants.contentType {
t.Errorf("%q. handlePatchDashboard() = %v, want %v", tt.name, content, tt.wants.contentType)
}
if eq, _ := jsonEqual(string(body), tt.wants.body); tt.wants.body != "" && !eq {
t.Errorf("%q. handlePatchDashboard() = \n***%v***\n,\nwant\n***%v***", tt.name, string(body), tt.wants.body)
if eq, diff, _ := jsonEqual(string(body), tt.wants.body); tt.wants.body != "" && !eq {
t.Errorf("%q. handlePatchDashboard() = ***%s***", tt.name, diff)
}
})
}
Expand Down Expand Up @@ -897,8 +897,8 @@ func TestService_handlePostDashboardCell(t *testing.T) {
if tt.wants.contentType != "" && content != tt.wants.contentType {
t.Errorf("%q. handlePostDashboardCell() = %v, want %v", tt.name, content, tt.wants.contentType)
}
if eq, _ := jsonEqual(string(body), tt.wants.body); tt.wants.body != "" && !eq {
t.Errorf("%q. handlePostDashboardCell() = \n***%v***\n,\nwant\n***%v***", tt.name, string(body), tt.wants.body)
if eq, diff, _ := jsonEqual(string(body), tt.wants.body); tt.wants.body != "" && !eq {
t.Errorf("%q. handlePostDashboardCell() = ***%s***", tt.name, diff)
}
})
}
Expand Down Expand Up @@ -981,8 +981,8 @@ func TestService_handleDeleteDashboardCell(t *testing.T) {
if tt.wants.contentType != "" && content != tt.wants.contentType {
t.Errorf("%q. handleDeleteDashboardCell() = %v, want %v", tt.name, content, tt.wants.contentType)
}
if eq, _ := jsonEqual(string(body), tt.wants.body); tt.wants.body != "" && !eq {
t.Errorf("%q. handleDeleteDashboardCell() = \n***%v***\n,\nwant\n***%v***", tt.name, string(body), tt.wants.body)
if eq, diff, _ := jsonEqual(string(body), tt.wants.body); tt.wants.body != "" && !eq {
t.Errorf("%q. handleDeleteDashboardCell() = ***%s***", tt.name, diff)
}
})
}
Expand Down Expand Up @@ -1119,8 +1119,8 @@ func TestService_handlePatchDashboardCell(t *testing.T) {
if tt.wants.contentType != "" && content != tt.wants.contentType {
t.Errorf("%q. handlePatchDashboardCell() = %v, want %v", tt.name, content, tt.wants.contentType)
}
if eq, _ := jsonEqual(string(body), tt.wants.body); tt.wants.body != "" && !eq {
t.Errorf("%q. handlePatchDashboardCell() = \n***%v***\n,\nwant\n***%v***", tt.name, string(body), tt.wants.body)
if eq, diff, _ := jsonEqual(string(body), tt.wants.body); tt.wants.body != "" && !eq {
t.Errorf("%q. handlePatchDashboardCell() = ***%s***", tt.name, diff)
}
})
}
Expand Down
4 changes: 2 additions & 2 deletions http/health_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ func TestHealthHandler(t *testing.T) {
if tt.wants.contentType != "" && content != tt.wants.contentType {
t.Errorf("%q. HealthHandler() = %v, want %v", tt.name, content, tt.wants.contentType)
}
if eq, _ := jsonEqual(string(body), tt.wants.body); tt.wants.body != "" && !eq {
t.Errorf("%q. HealthHandler() = \n***%v***\n,\nwant\n***%v***", tt.name, string(body), tt.wants.body)
if eq, diff, _ := jsonEqual(string(body), tt.wants.body); tt.wants.body != "" && !eq {
t.Errorf("%q. HealthHandler() = ***%s***", tt.name, diff)
}
})
}
Expand Down
12 changes: 6 additions & 6 deletions http/org_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,8 +142,8 @@ func TestSecretService_handleGetSecrets(t *testing.T) {
if tt.wants.contentType != "" && content != tt.wants.contentType {
t.Errorf("handleGetSecrets() = %v, want %v", content, tt.wants.contentType)
}
if eq, _ := jsonEqual(string(body), tt.wants.body); tt.wants.body != "" && !eq {
t.Errorf("handleGetSecrets() = \n***%v***\n,\nwant\n***%v***", string(body), tt.wants.body)
if eq, diff, _ := jsonEqual(string(body), tt.wants.body); tt.wants.body != "" && !eq {
t.Errorf("handleGetSecrets() = ***%s***", diff)
}

})
Expand Down Expand Up @@ -218,8 +218,8 @@ func TestSecretService_handlePatchSecrets(t *testing.T) {
if tt.wants.contentType != "" && content != tt.wants.contentType {
t.Errorf("handlePatchSecrets() = %v, want %v", content, tt.wants.contentType)
}
if eq, _ := jsonEqual(string(body), tt.wants.body); tt.wants.body != "" && !eq {
t.Errorf("handlePatchSecrets() = \n***%v***\n,\nwant\n***%v***", string(body), tt.wants.body)
if eq, diff, _ := jsonEqual(string(body), tt.wants.body); tt.wants.body != "" && !eq {
t.Errorf("handlePatchSecrets() = ***%s***", diff)
}

})
Expand Down Expand Up @@ -294,8 +294,8 @@ func TestSecretService_handleDeleteSecrets(t *testing.T) {
if tt.wants.contentType != "" && content != tt.wants.contentType {
t.Errorf("handleDeleteSecrets() = %v, want %v", content, tt.wants.contentType)
}
if eq, _ := jsonEqual(string(body), tt.wants.body); tt.wants.body != "" && !eq {
t.Errorf("handleDeleteSecrets() = \n***%v***\n,\nwant\n***%v***", string(body), tt.wants.body)
if eq, diff, _ := jsonEqual(string(body), tt.wants.body); tt.wants.body != "" && !eq {
t.Errorf("handleDeleteSecrets() = ***%s***", diff)
}

})
Expand Down
12 changes: 6 additions & 6 deletions http/router_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,8 @@ func TestRouter_NotFound(t *testing.T) {
if tt.wants.contentType != "" && content != tt.wants.contentType {
t.Errorf("%q. get %v, want %v", tt.name, content, tt.wants.contentType)
}
if eq, _ := jsonEqual(string(body), tt.wants.body); tt.wants.body != "" && !eq {
t.Errorf("%q. get\n***%v***\n,\nwant\n***%v***", tt.name, string(body), tt.wants.body)
if eq, diff, _ := jsonEqual(string(body), tt.wants.body); tt.wants.body != "" && !eq {
t.Errorf("%q. get ***%s***", tt.name, diff)
}
})
}
Expand Down Expand Up @@ -193,8 +193,8 @@ func TestRouter_Panic(t *testing.T) {
if tt.wants.contentType != "" && content != tt.wants.contentType {
t.Errorf("%q. get %v, want %v", tt.name, content, tt.wants.contentType)
}
if eq, _ := jsonEqual(string(body), tt.wants.body); tt.wants.body != "" && !eq {
t.Errorf("%q. get\n***%v***\n,\nwant\n***%v***", tt.name, string(body), tt.wants.body)
if eq, diff, _ := jsonEqual(string(body), tt.wants.body); tt.wants.body != "" && !eq {
t.Errorf("%q. get ***%s***", tt.name, diff)
}

})
Expand Down Expand Up @@ -290,8 +290,8 @@ func TestRouter_MethodNotAllowed(t *testing.T) {
if tt.wants.contentType != "" && content != tt.wants.contentType {
t.Errorf("%q. get %v, want %v", tt.name, content, tt.wants.contentType)
}
if eq, _ := jsonEqual(string(body), tt.wants.body); tt.wants.body != "" && !eq {
t.Errorf("%q. get\n***%v***\n,\nwant\n***%v***", tt.name, string(body), tt.wants.body)
if eq, diff, _ := jsonEqual(string(body), tt.wants.body); tt.wants.body != "" && !eq {
t.Errorf("%q. get ***%s***", tt.name, diff)
}

})
Expand Down
16 changes: 8 additions & 8 deletions http/task_service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,8 +162,8 @@ func TestTaskHandler_handleGetTasks(t *testing.T) {
if tt.wants.contentType != "" && content != tt.wants.contentType {
t.Errorf("%q. handleGetTasks() = %v, want %v", tt.name, content, tt.wants.contentType)
}
if eq, _ := jsonEqual(string(body), tt.wants.body); tt.wants.body != "" && !eq {
t.Errorf("%q. handleGetTasks() = \n***%v***\n,\nwant\n***%v***", tt.name, string(body), tt.wants.body)
if eq, diff, _ := jsonEqual(string(body), tt.wants.body); tt.wants.body != "" && !eq {
t.Errorf("%q. handleGetTasks() = ***%s***", tt.name, diff)
}
})
}
Expand Down Expand Up @@ -264,8 +264,8 @@ func TestTaskHandler_handlePostTasks(t *testing.T) {
if tt.wants.contentType != "" && content != tt.wants.contentType {
t.Errorf("%q. handlePostTask() = %v, want %v", tt.name, content, tt.wants.contentType)
}
if eq, _ := jsonEqual(string(body), tt.wants.body); tt.wants.body != "" && !eq {
t.Errorf("%q. handlePostTask() = \n***%v***\n,\nwant\n***%v***", tt.name, string(body), tt.wants.body)
if eq, diff, _ := jsonEqual(string(body), tt.wants.body); tt.wants.body != "" && !eq {
t.Errorf("%q. handlePostTask() = ***%s***", tt.name, diff)
}
})
}
Expand Down Expand Up @@ -368,8 +368,8 @@ func TestTaskHandler_handleGetRun(t *testing.T) {
if tt.wants.contentType != "" && content != tt.wants.contentType {
t.Errorf("%q. handleGetRun() = %v, want %v", tt.name, content, tt.wants.contentType)
}
if eq, _ := jsonEqual(string(body), tt.wants.body); tt.wants.body != "" && !eq {
t.Errorf("%q. handleGetRun() = \n***%v***\n,\nwant\n***%v***", tt.name, string(body), tt.wants.body)
if eq, diff, _ := jsonEqual(string(body), tt.wants.body); tt.wants.body != "" && !eq {
t.Errorf("%q. handleGetRun() = ***%s***", tt.name, diff)
}
})
}
Expand Down Expand Up @@ -476,8 +476,8 @@ func TestTaskHandler_handleGetRuns(t *testing.T) {
if tt.wants.contentType != "" && content != tt.wants.contentType {
t.Errorf("%q. handleGetRuns() = %v, want %v", tt.name, content, tt.wants.contentType)
}
if eq, _ := jsonEqual(string(body), tt.wants.body); tt.wants.body != "" && !eq {
t.Errorf("%q. handleGetRuns() = \n***%v***\n,\nwant\n***%v***", tt.name, string(body), tt.wants.body)
if eq, diff, _ := jsonEqual(string(body), tt.wants.body); tt.wants.body != "" && !eq {
t.Errorf("%q. handleGetRuns() = ***%s***", tt.name, diff)
}
})
}
Expand Down
Loading

0 comments on commit 7562c9a

Please sign in to comment.