Skip to content

Commit

Permalink
Fix go vet and use go test -race
Browse files Browse the repository at this point in the history
  • Loading branch information
danielnelson committed Apr 2, 2018
1 parent 19c102c commit 0aad487
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 35 deletions.
3 changes: 2 additions & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ jobs:
<<: *defaults
steps:
- checkout
- run: 'make ci-test'
- run: 'make deps'
- run: 'make test-ci'
release:
<<: *defaults
steps:
Expand Down
15 changes: 4 additions & 11 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,9 @@ ifdef VERSION
endif

all:
$(MAKE) fmtcheck
$(MAKE) deps
$(MAKE) telegraf

ci-test:
$(MAKE) deps
$(MAKE) fmtcheck
$(MAKE) vet
$(MAKE) test

deps:
go get -u github.com/golang/lint/golint
go get github.com/sparrc/gdm
Expand Down Expand Up @@ -62,9 +55,6 @@ fmtcheck:
fi
@echo '[INFO] done.'

lint:
golint ./...

test-windows:
go test ./plugins/inputs/ping/...
go test ./plugins/inputs/win_perf_counters/...
Expand All @@ -82,7 +72,10 @@ vet:
exit 1; \
fi

test-all: vet
test-ci: fmtcheck vet
go test -short./...

test-all: fmtcheck vet
go test ./...

package:
Expand Down
46 changes: 23 additions & 23 deletions plugins/inputs/http_response/http_response_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@ import (
)

// Receives a list with fields that are expected to be absent
func checkAbsentFields(t *testing.T, fields []string, acc testutil.Accumulator) {
func checkAbsentFields(t *testing.T, fields []string, acc *testutil.Accumulator) {
for _, field := range fields {
ok := acc.HasField("http_response", field)
require.False(t, ok)
}
}

// Receives a list with tags that are expected to be absent
func checkAbsentTags(t *testing.T, tags []string, acc testutil.Accumulator) {
func checkAbsentTags(t *testing.T, tags []string, acc *testutil.Accumulator) {
for _, tag := range tags {
ok := acc.HasTag("http_response", tag)
require.False(t, ok)
Expand All @@ -33,7 +33,7 @@ func checkAbsentTags(t *testing.T, tags []string, acc testutil.Accumulator) {

// Receives a dictionary and with expected fields and their values. If a value is nil, it will only check
// that the field exists, but not its contents
func checkFields(t *testing.T, fields map[string]interface{}, acc testutil.Accumulator) {
func checkFields(t *testing.T, fields map[string]interface{}, acc *testutil.Accumulator) {
for key, field := range fields {
switch v := field.(type) {
case int:
Expand All @@ -60,7 +60,7 @@ func checkFields(t *testing.T, fields map[string]interface{}, acc testutil.Accum

// Receives a dictionary and with expected tags and their values. If a value is nil, it will only check
// that the tag exists, but not its contents
func checkTags(t *testing.T, tags map[string]interface{}, acc testutil.Accumulator) {
func checkTags(t *testing.T, tags map[string]interface{}, acc *testutil.Accumulator) {
for key, tag := range tags {
switch v := tag.(type) {
case string:
Expand Down Expand Up @@ -118,7 +118,7 @@ func setUpTestMux() http.Handler {
return mux
}

func checkOutput(t *testing.T, acc testutil.Accumulator, presentFields map[string]interface{}, presentTags map[string]interface{}, absentFields []string, absentTags []string) {
func checkOutput(t *testing.T, acc *testutil.Accumulator, presentFields map[string]interface{}, presentTags map[string]interface{}, absentFields []string, absentTags []string) {
if presentFields != nil {
checkFields(t, presentFields, acc)
}
Expand Down Expand Up @@ -171,7 +171,7 @@ func TestHeaders(t *testing.T) {
"result": "success",
}
absentFields := []string{"response_string_match"}
checkOutput(t, acc, expectedFields, expectedTags, absentFields, nil)
checkOutput(t, &acc, expectedFields, expectedTags, absentFields, nil)
}

func TestFields(t *testing.T) {
Expand Down Expand Up @@ -207,7 +207,7 @@ func TestFields(t *testing.T) {
"result": "success",
}
absentFields := []string{"response_string_match"}
checkOutput(t, acc, expectedFields, expectedTags, absentFields, nil)
checkOutput(t, &acc, expectedFields, expectedTags, absentFields, nil)
}

func TestRedirects(t *testing.T) {
Expand Down Expand Up @@ -242,7 +242,7 @@ func TestRedirects(t *testing.T) {
"result": "success",
}
absentFields := []string{"response_string_match"}
checkOutput(t, acc, expectedFields, expectedTags, absentFields, nil)
checkOutput(t, &acc, expectedFields, expectedTags, absentFields, nil)

h = &HTTPResponse{
Address: ts.URL + "/badredirect",
Expand All @@ -269,10 +269,10 @@ func TestRedirects(t *testing.T) {
}
absentFields = []string{"http_response_code", "response_time", "response_string_match"}
absentTags := []string{"status_code"}
checkOutput(t, acc, expectedFields, expectedTags, nil, nil)
checkOutput(t, &acc, expectedFields, expectedTags, nil, nil)

expectedFields = map[string]interface{}{"result_type": "connection_failed"}
checkOutput(t, acc, expectedFields, expectedTags, absentFields, absentTags)
checkOutput(t, &acc, expectedFields, expectedTags, absentFields, absentTags)
}

func TestMethod(t *testing.T) {
Expand Down Expand Up @@ -307,7 +307,7 @@ func TestMethod(t *testing.T) {
"result": "success",
}
absentFields := []string{"response_string_match"}
checkOutput(t, acc, expectedFields, expectedTags, absentFields, nil)
checkOutput(t, &acc, expectedFields, expectedTags, absentFields, nil)

h = &HTTPResponse{
Address: ts.URL + "/mustbepostmethod",
Expand Down Expand Up @@ -336,7 +336,7 @@ func TestMethod(t *testing.T) {
"result": "success",
}
absentFields = []string{"response_string_match"}
checkOutput(t, acc, expectedFields, expectedTags, absentFields, nil)
checkOutput(t, &acc, expectedFields, expectedTags, absentFields, nil)

//check that lowercase methods work correctly
h = &HTTPResponse{
Expand Down Expand Up @@ -366,7 +366,7 @@ func TestMethod(t *testing.T) {
"result": "success",
}
absentFields = []string{"response_string_match"}
checkOutput(t, acc, expectedFields, expectedTags, absentFields, nil)
checkOutput(t, &acc, expectedFields, expectedTags, absentFields, nil)
}

func TestBody(t *testing.T) {
Expand Down Expand Up @@ -401,7 +401,7 @@ func TestBody(t *testing.T) {
"result": "success",
}
absentFields := []string{"response_string_match"}
checkOutput(t, acc, expectedFields, expectedTags, absentFields, nil)
checkOutput(t, &acc, expectedFields, expectedTags, absentFields, nil)

h = &HTTPResponse{
Address: ts.URL + "/musthaveabody",
Expand All @@ -428,7 +428,7 @@ func TestBody(t *testing.T) {
"result": "success",
}
absentFields = []string{"response_string_match"}
checkOutput(t, acc, expectedFields, expectedTags, absentFields, nil)
checkOutput(t, &acc, expectedFields, expectedTags, absentFields, nil)
}

func TestStringMatch(t *testing.T) {
Expand Down Expand Up @@ -464,7 +464,7 @@ func TestStringMatch(t *testing.T) {
"status_code": "200",
"result": "success",
}
checkOutput(t, acc, expectedFields, expectedTags, nil, nil)
checkOutput(t, &acc, expectedFields, expectedTags, nil, nil)
}

func TestStringMatchJson(t *testing.T) {
Expand Down Expand Up @@ -500,7 +500,7 @@ func TestStringMatchJson(t *testing.T) {
"status_code": "200",
"result": "success",
}
checkOutput(t, acc, expectedFields, expectedTags, nil, nil)
checkOutput(t, &acc, expectedFields, expectedTags, nil, nil)
}

func TestStringMatchFail(t *testing.T) {
Expand Down Expand Up @@ -537,7 +537,7 @@ func TestStringMatchFail(t *testing.T) {
"status_code": "200",
"result": "response_string_mismatch",
}
checkOutput(t, acc, expectedFields, expectedTags, nil, nil)
checkOutput(t, &acc, expectedFields, expectedTags, nil, nil)
}

func TestTimeout(t *testing.T) {
Expand Down Expand Up @@ -574,7 +574,7 @@ func TestTimeout(t *testing.T) {
}
absentFields := []string{"http_response_code", "response_time", "response_string_match"}
absentTags := []string{"status_code"}
checkOutput(t, acc, expectedFields, expectedTags, absentFields, absentTags)
checkOutput(t, &acc, expectedFields, expectedTags, absentFields, absentTags)
}

func TestPluginErrors(t *testing.T) {
Expand All @@ -601,7 +601,7 @@ func TestPluginErrors(t *testing.T) {

absentFields := []string{"http_response_code", "response_time", "response_string_match", "result_type", "result_code"}
absentTags := []string{"status_code", "result", "server", "method"}
checkOutput(t, acc, nil, nil, absentFields, absentTags)
checkOutput(t, &acc, nil, nil, absentFields, absentTags)

// Attempt to read empty body test
h = &HTTPResponse{
Expand Down Expand Up @@ -630,7 +630,7 @@ func TestPluginErrors(t *testing.T) {
"status_code": "301",
"result": "body_read_error",
}
checkOutput(t, acc, expectedFields, expectedTags, nil, nil)
checkOutput(t, &acc, expectedFields, expectedTags, nil, nil)
}

func TestNetworkErrors(t *testing.T) {
Expand Down Expand Up @@ -658,7 +658,7 @@ func TestNetworkErrors(t *testing.T) {
}
absentFields := []string{"http_response_code", "response_time", "response_string_match"}
absentTags := []string{"status_code"}
checkOutput(t, acc, expectedFields, expectedTags, absentFields, absentTags)
checkOutput(t, &acc, expectedFields, expectedTags, absentFields, absentTags)

// Connecton failed
h = &HTTPResponse{
Expand All @@ -684,5 +684,5 @@ func TestNetworkErrors(t *testing.T) {
}
absentFields = []string{"http_response_code", "response_time", "response_string_match"}
absentTags = []string{"status_code"}
checkOutput(t, acc, expectedFields, expectedTags, absentFields, absentTags)
checkOutput(t, &acc, expectedFields, expectedTags, absentFields, absentTags)
}

0 comments on commit 0aad487

Please sign in to comment.