Fix go vet and use go test -race
This commit is contained in:
parent
7079c6ee60
commit
e775c886b7
|
@ -9,7 +9,8 @@ jobs:
|
||||||
<<: *defaults
|
<<: *defaults
|
||||||
steps:
|
steps:
|
||||||
- checkout
|
- checkout
|
||||||
- run: 'make ci-test'
|
- run: 'make deps'
|
||||||
|
- run: 'make test-ci'
|
||||||
release:
|
release:
|
||||||
<<: *defaults
|
<<: *defaults
|
||||||
steps:
|
steps:
|
||||||
|
|
15
Makefile
15
Makefile
|
@ -20,16 +20,9 @@ ifdef VERSION
|
||||||
endif
|
endif
|
||||||
|
|
||||||
all:
|
all:
|
||||||
$(MAKE) fmtcheck
|
|
||||||
$(MAKE) deps
|
$(MAKE) deps
|
||||||
$(MAKE) telegraf
|
$(MAKE) telegraf
|
||||||
|
|
||||||
ci-test:
|
|
||||||
$(MAKE) deps
|
|
||||||
$(MAKE) fmtcheck
|
|
||||||
$(MAKE) vet
|
|
||||||
$(MAKE) test
|
|
||||||
|
|
||||||
deps:
|
deps:
|
||||||
go get -u github.com/golang/lint/golint
|
go get -u github.com/golang/lint/golint
|
||||||
go get github.com/sparrc/gdm
|
go get github.com/sparrc/gdm
|
||||||
|
@ -62,9 +55,6 @@ fmtcheck:
|
||||||
fi
|
fi
|
||||||
@echo '[INFO] done.'
|
@echo '[INFO] done.'
|
||||||
|
|
||||||
lint:
|
|
||||||
golint ./...
|
|
||||||
|
|
||||||
test-windows:
|
test-windows:
|
||||||
go test ./plugins/inputs/ping/...
|
go test ./plugins/inputs/ping/...
|
||||||
go test ./plugins/inputs/win_perf_counters/...
|
go test ./plugins/inputs/win_perf_counters/...
|
||||||
|
@ -82,7 +72,10 @@ vet:
|
||||||
exit 1; \
|
exit 1; \
|
||||||
fi
|
fi
|
||||||
|
|
||||||
test-all: vet
|
test-ci: fmtcheck vet
|
||||||
|
go test -short./...
|
||||||
|
|
||||||
|
test-all: fmtcheck vet
|
||||||
go test ./...
|
go test ./...
|
||||||
|
|
||||||
package:
|
package:
|
||||||
|
|
|
@ -16,7 +16,7 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
// Receives a list with fields that are expected to be absent
|
// 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 {
|
for _, field := range fields {
|
||||||
ok := acc.HasField("http_response", field)
|
ok := acc.HasField("http_response", field)
|
||||||
require.False(t, ok)
|
require.False(t, ok)
|
||||||
|
@ -24,7 +24,7 @@ func checkAbsentFields(t *testing.T, fields []string, acc testutil.Accumulator)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Receives a list with tags that are expected to be absent
|
// 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 {
|
for _, tag := range tags {
|
||||||
ok := acc.HasTag("http_response", tag)
|
ok := acc.HasTag("http_response", tag)
|
||||||
require.False(t, ok)
|
require.False(t, ok)
|
||||||
|
@ -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
|
// 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
|
// 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 {
|
for key, field := range fields {
|
||||||
switch v := field.(type) {
|
switch v := field.(type) {
|
||||||
case int:
|
case int:
|
||||||
|
@ -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
|
// 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
|
// 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 {
|
for key, tag := range tags {
|
||||||
switch v := tag.(type) {
|
switch v := tag.(type) {
|
||||||
case string:
|
case string:
|
||||||
|
@ -118,7 +118,7 @@ func setUpTestMux() http.Handler {
|
||||||
return mux
|
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 {
|
if presentFields != nil {
|
||||||
checkFields(t, presentFields, acc)
|
checkFields(t, presentFields, acc)
|
||||||
}
|
}
|
||||||
|
@ -171,7 +171,7 @@ func TestHeaders(t *testing.T) {
|
||||||
"result": "success",
|
"result": "success",
|
||||||
}
|
}
|
||||||
absentFields := []string{"response_string_match"}
|
absentFields := []string{"response_string_match"}
|
||||||
checkOutput(t, acc, expectedFields, expectedTags, absentFields, nil)
|
checkOutput(t, &acc, expectedFields, expectedTags, absentFields, nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestFields(t *testing.T) {
|
func TestFields(t *testing.T) {
|
||||||
|
@ -207,7 +207,7 @@ func TestFields(t *testing.T) {
|
||||||
"result": "success",
|
"result": "success",
|
||||||
}
|
}
|
||||||
absentFields := []string{"response_string_match"}
|
absentFields := []string{"response_string_match"}
|
||||||
checkOutput(t, acc, expectedFields, expectedTags, absentFields, nil)
|
checkOutput(t, &acc, expectedFields, expectedTags, absentFields, nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestRedirects(t *testing.T) {
|
func TestRedirects(t *testing.T) {
|
||||||
|
@ -242,7 +242,7 @@ func TestRedirects(t *testing.T) {
|
||||||
"result": "success",
|
"result": "success",
|
||||||
}
|
}
|
||||||
absentFields := []string{"response_string_match"}
|
absentFields := []string{"response_string_match"}
|
||||||
checkOutput(t, acc, expectedFields, expectedTags, absentFields, nil)
|
checkOutput(t, &acc, expectedFields, expectedTags, absentFields, nil)
|
||||||
|
|
||||||
h = &HTTPResponse{
|
h = &HTTPResponse{
|
||||||
Address: ts.URL + "/badredirect",
|
Address: ts.URL + "/badredirect",
|
||||||
|
@ -269,10 +269,10 @@ func TestRedirects(t *testing.T) {
|
||||||
}
|
}
|
||||||
absentFields = []string{"http_response_code", "response_time", "response_string_match"}
|
absentFields = []string{"http_response_code", "response_time", "response_string_match"}
|
||||||
absentTags := []string{"status_code"}
|
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"}
|
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) {
|
func TestMethod(t *testing.T) {
|
||||||
|
@ -307,7 +307,7 @@ func TestMethod(t *testing.T) {
|
||||||
"result": "success",
|
"result": "success",
|
||||||
}
|
}
|
||||||
absentFields := []string{"response_string_match"}
|
absentFields := []string{"response_string_match"}
|
||||||
checkOutput(t, acc, expectedFields, expectedTags, absentFields, nil)
|
checkOutput(t, &acc, expectedFields, expectedTags, absentFields, nil)
|
||||||
|
|
||||||
h = &HTTPResponse{
|
h = &HTTPResponse{
|
||||||
Address: ts.URL + "/mustbepostmethod",
|
Address: ts.URL + "/mustbepostmethod",
|
||||||
|
@ -336,7 +336,7 @@ func TestMethod(t *testing.T) {
|
||||||
"result": "success",
|
"result": "success",
|
||||||
}
|
}
|
||||||
absentFields = []string{"response_string_match"}
|
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
|
//check that lowercase methods work correctly
|
||||||
h = &HTTPResponse{
|
h = &HTTPResponse{
|
||||||
|
@ -366,7 +366,7 @@ func TestMethod(t *testing.T) {
|
||||||
"result": "success",
|
"result": "success",
|
||||||
}
|
}
|
||||||
absentFields = []string{"response_string_match"}
|
absentFields = []string{"response_string_match"}
|
||||||
checkOutput(t, acc, expectedFields, expectedTags, absentFields, nil)
|
checkOutput(t, &acc, expectedFields, expectedTags, absentFields, nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestBody(t *testing.T) {
|
func TestBody(t *testing.T) {
|
||||||
|
@ -401,7 +401,7 @@ func TestBody(t *testing.T) {
|
||||||
"result": "success",
|
"result": "success",
|
||||||
}
|
}
|
||||||
absentFields := []string{"response_string_match"}
|
absentFields := []string{"response_string_match"}
|
||||||
checkOutput(t, acc, expectedFields, expectedTags, absentFields, nil)
|
checkOutput(t, &acc, expectedFields, expectedTags, absentFields, nil)
|
||||||
|
|
||||||
h = &HTTPResponse{
|
h = &HTTPResponse{
|
||||||
Address: ts.URL + "/musthaveabody",
|
Address: ts.URL + "/musthaveabody",
|
||||||
|
@ -428,7 +428,7 @@ func TestBody(t *testing.T) {
|
||||||
"result": "success",
|
"result": "success",
|
||||||
}
|
}
|
||||||
absentFields = []string{"response_string_match"}
|
absentFields = []string{"response_string_match"}
|
||||||
checkOutput(t, acc, expectedFields, expectedTags, absentFields, nil)
|
checkOutput(t, &acc, expectedFields, expectedTags, absentFields, nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestStringMatch(t *testing.T) {
|
func TestStringMatch(t *testing.T) {
|
||||||
|
@ -464,7 +464,7 @@ func TestStringMatch(t *testing.T) {
|
||||||
"status_code": "200",
|
"status_code": "200",
|
||||||
"result": "success",
|
"result": "success",
|
||||||
}
|
}
|
||||||
checkOutput(t, acc, expectedFields, expectedTags, nil, nil)
|
checkOutput(t, &acc, expectedFields, expectedTags, nil, nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestStringMatchJson(t *testing.T) {
|
func TestStringMatchJson(t *testing.T) {
|
||||||
|
@ -500,7 +500,7 @@ func TestStringMatchJson(t *testing.T) {
|
||||||
"status_code": "200",
|
"status_code": "200",
|
||||||
"result": "success",
|
"result": "success",
|
||||||
}
|
}
|
||||||
checkOutput(t, acc, expectedFields, expectedTags, nil, nil)
|
checkOutput(t, &acc, expectedFields, expectedTags, nil, nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestStringMatchFail(t *testing.T) {
|
func TestStringMatchFail(t *testing.T) {
|
||||||
|
@ -537,7 +537,7 @@ func TestStringMatchFail(t *testing.T) {
|
||||||
"status_code": "200",
|
"status_code": "200",
|
||||||
"result": "response_string_mismatch",
|
"result": "response_string_mismatch",
|
||||||
}
|
}
|
||||||
checkOutput(t, acc, expectedFields, expectedTags, nil, nil)
|
checkOutput(t, &acc, expectedFields, expectedTags, nil, nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestTimeout(t *testing.T) {
|
func TestTimeout(t *testing.T) {
|
||||||
|
@ -574,7 +574,7 @@ func TestTimeout(t *testing.T) {
|
||||||
}
|
}
|
||||||
absentFields := []string{"http_response_code", "response_time", "response_string_match"}
|
absentFields := []string{"http_response_code", "response_time", "response_string_match"}
|
||||||
absentTags := []string{"status_code"}
|
absentTags := []string{"status_code"}
|
||||||
checkOutput(t, acc, expectedFields, expectedTags, absentFields, absentTags)
|
checkOutput(t, &acc, expectedFields, expectedTags, absentFields, absentTags)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestPluginErrors(t *testing.T) {
|
func TestPluginErrors(t *testing.T) {
|
||||||
|
@ -601,7 +601,7 @@ func TestPluginErrors(t *testing.T) {
|
||||||
|
|
||||||
absentFields := []string{"http_response_code", "response_time", "response_string_match", "result_type", "result_code"}
|
absentFields := []string{"http_response_code", "response_time", "response_string_match", "result_type", "result_code"}
|
||||||
absentTags := []string{"status_code", "result", "server", "method"}
|
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
|
// Attempt to read empty body test
|
||||||
h = &HTTPResponse{
|
h = &HTTPResponse{
|
||||||
|
@ -630,7 +630,7 @@ func TestPluginErrors(t *testing.T) {
|
||||||
"status_code": "301",
|
"status_code": "301",
|
||||||
"result": "body_read_error",
|
"result": "body_read_error",
|
||||||
}
|
}
|
||||||
checkOutput(t, acc, expectedFields, expectedTags, nil, nil)
|
checkOutput(t, &acc, expectedFields, expectedTags, nil, nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestNetworkErrors(t *testing.T) {
|
func TestNetworkErrors(t *testing.T) {
|
||||||
|
@ -658,7 +658,7 @@ func TestNetworkErrors(t *testing.T) {
|
||||||
}
|
}
|
||||||
absentFields := []string{"http_response_code", "response_time", "response_string_match"}
|
absentFields := []string{"http_response_code", "response_time", "response_string_match"}
|
||||||
absentTags := []string{"status_code"}
|
absentTags := []string{"status_code"}
|
||||||
checkOutput(t, acc, expectedFields, expectedTags, absentFields, absentTags)
|
checkOutput(t, &acc, expectedFields, expectedTags, absentFields, absentTags)
|
||||||
|
|
||||||
// Connecton failed
|
// Connecton failed
|
||||||
h = &HTTPResponse{
|
h = &HTTPResponse{
|
||||||
|
@ -684,5 +684,5 @@ func TestNetworkErrors(t *testing.T) {
|
||||||
}
|
}
|
||||||
absentFields = []string{"http_response_code", "response_time", "response_string_match"}
|
absentFields = []string{"http_response_code", "response_time", "response_string_match"}
|
||||||
absentTags = []string{"status_code"}
|
absentTags = []string{"status_code"}
|
||||||
checkOutput(t, acc, expectedFields, expectedTags, absentFields, absentTags)
|
checkOutput(t, &acc, expectedFields, expectedTags, absentFields, absentTags)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue