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

Run go fmt and lint on test files #1709

Merged
merged 3 commits into from
Aug 5, 2019
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
6 changes: 3 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ ALL_SRC := $(shell find . -name '*.go' \
-not -name '.*' \
-not -name 'gen_assets.go' \
-not -name 'mocks*' \
-not -name '*_test.go' \
-not -name 'model.pb.go' \
-not -name 'model_test.pb.go' \
-not -name 'storage_test.pb.go' \
Expand Down Expand Up @@ -126,7 +125,7 @@ nocover:
.PHONY: fmt
fmt:
./scripts/import-order-cleanup.sh inplace
@echo Running go fmt...
@echo Running go fmt on ALL_SRC ...
@$(GOFMT) -e -s -l -w $(ALL_SRC)
./scripts/updateLicenses.sh

Expand All @@ -149,6 +148,7 @@ lint-staticcheck:
lint: lint-staticcheck lint-gosec
$(GOVET) ./...
$(MAKE) go-lint
@echo Running go fmt on ALL_SRC ...
@$(GOFMT) -e -s -l $(ALL_SRC) > $(FMT_LOG)
@./scripts/updateLicenses.sh >> $(FMT_LOG)
@./scripts/import-order-cleanup.sh stdout > $(IMPORT_LOG)
Expand Down Expand Up @@ -284,7 +284,7 @@ build-crossdock-ui-placeholder:
[ -e cmd/query/app/ui/actual/gen_assets.go ] || cp cmd/query/app/ui/placeholder/gen_assets.go cmd/query/app/ui/actual/gen_assets.go

.PHONY: build-crossdock
build-crossdock: build-crossdock-ui-placeholder build-binaries-linux build-crossdock-linux docker-images-cassandra docker-images-jaeger-backend
build-crossdock: build-crossdock-ui-placeholder build-binaries-linux build-crossdock-linux docker-images-cassandra docker-images-jaeger-backend
docker build -t $(DOCKER_NAMESPACE)/test-driver:${DOCKER_TAG} crossdock/
@echo "Finished building test-driver ==============" ; \

Expand Down
6 changes: 3 additions & 3 deletions cmd/agent/app/reporter/flags_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,9 @@ func TestBindFlags(t *testing.T) {
b.InitFromViper(v)

expectedTags := map[string]string{
"key" : "value",
"envVar1" : "envVal1",
"envVar2" : "defaultVal2",
"key": "value",
"envVar1": "envVal1",
"envVar2": "defaultVal2",
}

assert.Equal(t, Type("grpc"), b.ReporterType)
Expand Down
6 changes: 3 additions & 3 deletions cmd/collector/app/tchannel_handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,15 @@ func TestTChannelHandler(t *testing.T) {
zh := &mockZipkinHandler{}
h := NewTChannelHandler(jh, zh)
h.SubmitBatches(nil, []*jaeger.Batch{
&jaeger.Batch{
{
Spans: []*jaeger.Span{
&jaeger.Span{OperationName: "jaeger"},
{OperationName: "jaeger"},
},
},
})
assert.Len(t, jh.getBatches(), 1)
h.SubmitZipkinBatch(nil, []*zipkincore.Span{
&zipkincore.Span{
{
Name: "zipkin",
},
})
Expand Down
6 changes: 3 additions & 3 deletions cmd/docs/command_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@ import (
)

func TestOutputFormats(t *testing.T) {
tests := []struct{
tests := []struct {
file string
flag string
err string
err string
}{
{file: "docs.md"},
{file: "docs.1", flag: "--format=man"},
Expand All @@ -54,7 +54,7 @@ func TestOutputFormats(t *testing.T) {

func TestDocsForParent(t *testing.T) {
parent := &cobra.Command{
Use: "root_command",
Use: "root_command",
Short: "some description",
}
v := viper.New()
Expand Down
2 changes: 1 addition & 1 deletion cmd/query/app/grpc_handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@ import (
"testing"
"time"

"google.golang.org/grpc/status"
"github.com/opentracing/opentracing-go"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/mock"
"github.com/stretchr/testify/require"
"go.uber.org/zap"
"google.golang.org/grpc"
"google.golang.org/grpc/status"

"github.com/jaegertracing/jaeger/cmd/query/app/querysvc"
"github.com/jaegertracing/jaeger/model"
Expand Down
2 changes: 1 addition & 1 deletion cmd/query/app/handler_archive_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ func TestArchiveTrace_TraceNotFound(t *testing.T) {
ts.spanReader.On("GetTrace", mock.AnythingOfType("*context.valueCtx"), mock.AnythingOfType("model.TraceID")).
Return(nil, spanstore.ErrTraceNotFound).Once()
var response structuredResponse
err := postJSON(ts.server.URL+"/api/archive/" + mockTraceID.String(), []string{}, &response)
err := postJSON(ts.server.URL+"/api/archive/"+mockTraceID.String(), []string{}, &response)
assert.EqualError(t, err, `404 error from server: {"data":null,"total":0,"limit":0,"offset":0,"errors":[{"code":404,"msg":"trace not found"}]}`+"\n")
}, querysvc.QueryServiceOptions{ArchiveSpanReader: mockReader, ArchiveSpanWriter: mockWriter})
}
Expand Down
20 changes: 9 additions & 11 deletions cmd/query/app/token_propagation_hander_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@ import (
"github.com/jaegertracing/jaeger/storage/spanstore"
)


func Test_bearTokenPropagationHandler(t *testing.T) {
func Test_bearTokenPropagationHandler(t *testing.T) {
logger := zap.NewNop()
bearerToken := "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiJhZG1pbiIsIm5hbWUiOiJKb2huIERvZSIsImlhdCI"

Expand Down Expand Up @@ -57,13 +56,12 @@ func Test_bearTokenPropagationHandler(t *testing.T) {
headerName string
handler func(stop *sync.WaitGroup) http.HandlerFunc
}{
{ name:"Bearer token", sendHeader: true, headerName:"Authorization", headerValue: "Bearer " + bearerToken, handler:validTokenHandler},
{ name:"Raw bearer token",sendHeader: true, headerName:"Authorization", headerValue: bearerToken, handler:validTokenHandler},
{ name:"No headerValue", sendHeader: false, headerName:"Authorization", handler:emptyHandler},
{ name:"Basic Auth", sendHeader: true, headerName:"Authorization", headerValue: "Basic " + bearerToken, handler:emptyHandler},
{ name:"X-Forwarded-Access-Token", headerName:"X-Forwarded-Access-Token", sendHeader: true, headerValue: "Bearer " + bearerToken, handler:validTokenHandler},
{ name:"Invalid header", headerName:"X-Forwarded-Access-Token", sendHeader: true, headerValue: "Bearer " + bearerToken + " another stuff", handler:emptyHandler},

{name: "Bearer token", sendHeader: true, headerName: "Authorization", headerValue: "Bearer " + bearerToken, handler: validTokenHandler},
{name: "Raw bearer token", sendHeader: true, headerName: "Authorization", headerValue: bearerToken, handler: validTokenHandler},
{name: "No headerValue", sendHeader: false, headerName: "Authorization", handler: emptyHandler},
{name: "Basic Auth", sendHeader: true, headerName: "Authorization", headerValue: "Basic " + bearerToken, handler: emptyHandler},
{name: "X-Forwarded-Access-Token", headerName: "X-Forwarded-Access-Token", sendHeader: true, headerValue: "Bearer " + bearerToken, handler: validTokenHandler},
{name: "Invalid header", headerName: "X-Forwarded-Access-Token", sendHeader: true, headerValue: "Bearer " + bearerToken + " another stuff", handler: emptyHandler},
}

for _, testCase := range testCases {
Expand All @@ -73,8 +71,8 @@ func Test_bearTokenPropagationHandler(t *testing.T) {
r := bearerTokenPropagationHandler(logger, testCase.handler(&stop))
server := httptest.NewServer(r)
defer server.Close()
req , err := http.NewRequest("GET", server.URL, nil)
assert.Nil(t,err)
req, err := http.NewRequest("GET", server.URL, nil)
assert.Nil(t, err)
if testCase.sendHeader {
req.Header.Add(testCase.headerName, testCase.headerValue)
}
Expand Down
2 changes: 1 addition & 1 deletion plugin/storage/badger/spanstore/cache_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ import (
"testing"
"time"

"github.com/stretchr/testify/assert"
"github.com/dgraph-io/badger"
"github.com/stretchr/testify/assert"

"github.com/jaegertracing/jaeger/model"
)
Expand Down
4 changes: 2 additions & 2 deletions plugin/storage/badger/spanstore/read_write_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func TestWriteReadBack(t *testing.T) {
spans := 3

dummyKv := []model.KeyValue{
model.KeyValue{
{
Key: "key",
VType: model.StringType,
VStr: "value",
Expand All @@ -66,7 +66,7 @@ func TestWriteReadBack(t *testing.T) {
Duration: time.Duration(i + j),
Tags: dummyKv,
Logs: []model.Log{
model.Log{
{
Timestamp: tid,
Fields: dummyKv,
},
Expand Down
4 changes: 2 additions & 2 deletions plugin/storage/badger/spanstore/rw_internal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ func createDummySpan() model.Span {
tid := time.Now()

dummyKv := []model.KeyValue{
model.KeyValue{
{
Key: "key",
VType: model.StringType,
VStr: "value",
Expand All @@ -167,7 +167,7 @@ func createDummySpan() model.Span {
Duration: time.Duration(1 * time.Millisecond),
Tags: dummyKv,
Logs: []model.Log{
model.Log{
{
Timestamp: tid,
Fields: dummyKv,
},
Expand Down
4 changes: 2 additions & 2 deletions plugin/storage/cassandra/spanstore/writer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ func TestSpanWriter(t *testing.T) {
},
},
{
caption: "add span to operation name index",
caption: "add span to operation name index",
serviceOperationNameQueryError: errors.New("serviceOperationNameQueryError"),
expectedError: "Failed to index operation name: failed to Exec query 'select from service_operation_index': serviceOperationNameQueryError",
expectedLogs: []string{
Expand All @@ -132,7 +132,7 @@ func TestSpanWriter(t *testing.T) {
},
},
{
caption: "add duration with no operation name",
caption: "add duration with no operation name",
durationNoOperationQueryError: errors.New("durationNoOperationError"),
expectedError: "Failed to index duration: failed to Exec query 'select from duration_index': durationNoOperationError",
expectedLogs: []string{
Expand Down
12 changes: 6 additions & 6 deletions plugin/storage/es/dependencystore/storage_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,8 @@ func TestGetDependencies(t *testing.T) {
searchError error
expectedError string
expectedOutput []model.DependencyLink
indexPrefix string
indices []interface{}
indexPrefix string
indices []interface{}
}{
{
searchResult: createSearchResult(goodDependencies),
Expand All @@ -146,18 +146,18 @@ func TestGetDependencies(t *testing.T) {
{
searchResult: createSearchResult(badDependencies),
expectedError: "Unmarshalling ElasticSearch documents failed",
indices: []interface{}{"jaeger-dependencies-1995-04-21", "jaeger-dependencies-1995-04-20"},
indices: []interface{}{"jaeger-dependencies-1995-04-21", "jaeger-dependencies-1995-04-20"},
},
{
searchError: errors.New("search failure"),
expectedError: "Failed to search for dependencies: search failure",
indices: []interface{}{"jaeger-dependencies-1995-04-21", "jaeger-dependencies-1995-04-20"},
indices: []interface{}{"jaeger-dependencies-1995-04-21", "jaeger-dependencies-1995-04-20"},
},
{
searchError: errors.New("search failure"),
expectedError: "Failed to search for dependencies: search failure",
indexPrefix: "foo",
indices: []interface{}{"foo-jaeger-dependencies-1995-04-21", "foo-jaeger-dependencies-1995-04-20"},
indexPrefix: "foo",
indices: []interface{}{"foo-jaeger-dependencies-1995-04-21", "foo-jaeger-dependencies-1995-04-20"},
},
}
for _, testCase := range testCases {
Expand Down
6 changes: 3 additions & 3 deletions plugin/storage/es/factory_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ import (
"strings"
"testing"

"github.com/stretchr/testify/mock"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/mock"
"github.com/stretchr/testify/require"
"github.com/uber/jaeger-lib/metrics"
"go.uber.org/zap"
Expand All @@ -40,7 +40,7 @@ var _ storage.Factory = new(Factory)

type mockClientBuilder struct {
escfg.Configuration
err error
err error
createTemplateError error
}

Expand Down Expand Up @@ -68,7 +68,7 @@ func TestElasticsearchFactory(t *testing.T) {
assert.EqualError(t, f.Initialize(metrics.NullFactory, zap.NewNop()), "failed to create primary Elasticsearch client: made-up error")

f.primaryConfig = &mockClientBuilder{}
f.archiveConfig = &mockClientBuilder{err: errors.New("made-up error2"), Configuration:escfg.Configuration{Enabled:true}}
f.archiveConfig = &mockClientBuilder{err: errors.New("made-up error2"), Configuration: escfg.Configuration{Enabled: true}}
assert.EqualError(t, f.Initialize(metrics.NullFactory, zap.NewNop()), "failed to create archive Elasticsearch client: made-up error2")

f.archiveConfig = &mockClientBuilder{}
Expand Down
2 changes: 1 addition & 1 deletion plugin/storage/es/spanstore/dbmodel/to_domain_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,7 @@ func TestTagsMap(t *testing.T) {
if test.err != nil {
assert.Equal(t, test.err.Error(), err.Error())
require.Nil(t, tags)
} else {
} else {
require.NoError(t, err)
assert.Equal(t, test.expected, tags)
}
Expand Down
60 changes: 30 additions & 30 deletions plugin/storage/es/spanstore/reader_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,30 +145,30 @@ func TestSpanReaderIndices(t *testing.T) {
date := time.Now()
dateFormat := date.UTC().Format("2006-01-02")
testCases := []struct {
index string
params SpanReaderParams
index string
params SpanReaderParams
}{
{params:SpanReaderParams{Client:client, Logger: logger, MetricsFactory: metricsFactory,
IndexPrefix:"", Archive: false},
index: spanIndex+dateFormat},
{params:SpanReaderParams{Client:client, Logger: logger, MetricsFactory: metricsFactory,
IndexPrefix:"", UseReadWriteAliases: true},
index: spanIndex+"read"},
{params:SpanReaderParams{Client:client, Logger: logger, MetricsFactory: metricsFactory,
IndexPrefix:"foo:", Archive: false},
index: "foo:"+indexPrefixSeparator+spanIndex+dateFormat},
{params:SpanReaderParams{Client:client, Logger: logger, MetricsFactory: metricsFactory,
IndexPrefix:"foo:", UseReadWriteAliases: true},
index: "foo:-"+spanIndex+"read"},
{params:SpanReaderParams{Client:client, Logger: logger, MetricsFactory: metricsFactory,
IndexPrefix:"", Archive: true},
index: spanIndex+archiveIndexSuffix},
{params:SpanReaderParams{Client:client, Logger: logger, MetricsFactory: metricsFactory,
IndexPrefix:"foo:", Archive: true},
index: "foo:"+indexPrefixSeparator+spanIndex+archiveIndexSuffix},
{params:SpanReaderParams{Client:client, Logger: logger, MetricsFactory: metricsFactory,
IndexPrefix:"foo:", Archive: true, UseReadWriteAliases:true},
index: "foo:"+indexPrefixSeparator+spanIndex+archiveReadIndexSuffix},
{params: SpanReaderParams{Client: client, Logger: logger, MetricsFactory: metricsFactory,
IndexPrefix: "", Archive: false},
index: spanIndex + dateFormat},
{params: SpanReaderParams{Client: client, Logger: logger, MetricsFactory: metricsFactory,
IndexPrefix: "", UseReadWriteAliases: true},
index: spanIndex + "read"},
{params: SpanReaderParams{Client: client, Logger: logger, MetricsFactory: metricsFactory,
IndexPrefix: "foo:", Archive: false},
index: "foo:" + indexPrefixSeparator + spanIndex + dateFormat},
{params: SpanReaderParams{Client: client, Logger: logger, MetricsFactory: metricsFactory,
IndexPrefix: "foo:", UseReadWriteAliases: true},
index: "foo:-" + spanIndex + "read"},
{params: SpanReaderParams{Client: client, Logger: logger, MetricsFactory: metricsFactory,
IndexPrefix: "", Archive: true},
index: spanIndex + archiveIndexSuffix},
{params: SpanReaderParams{Client: client, Logger: logger, MetricsFactory: metricsFactory,
IndexPrefix: "foo:", Archive: true},
index: "foo:" + indexPrefixSeparator + spanIndex + archiveIndexSuffix},
{params: SpanReaderParams{Client: client, Logger: logger, MetricsFactory: metricsFactory,
IndexPrefix: "foo:", Archive: true, UseReadWriteAliases: true},
index: "foo:" + indexPrefixSeparator + spanIndex + archiveReadIndexSuffix},
}
for _, testCase := range testCases {
r := NewSpanReader(testCase.params)
Expand Down Expand Up @@ -208,19 +208,19 @@ func TestSpanReader_GetTrace(t *testing.T) {
func TestSpanReader_multiRead_followUp_query(t *testing.T) {
withSpanReader(func(r *spanReaderTest) {
now := time.Now()
spanID1 := dbmodel.Span{SpanID: "0", TraceID:"1", StartTime: model.TimeAsEpochMicroseconds(now)}
spanID1 := dbmodel.Span{SpanID: "0", TraceID: "1", StartTime: model.TimeAsEpochMicroseconds(now)}
spanBytesID1, err := json.Marshal(spanID1)
require.NoError(t, err)
spanID2 := dbmodel.Span{SpanID: "0", TraceID:"2", StartTime: model.TimeAsEpochMicroseconds(now)}
spanID2 := dbmodel.Span{SpanID: "0", TraceID: "2", StartTime: model.TimeAsEpochMicroseconds(now)}
spanBytesID2, err := json.Marshal(spanID2)
require.NoError(t, err)

id1Query := elastic.NewTermQuery("traceID", model.TraceID{High: 0, Low:1}.String())
id1Query := elastic.NewTermQuery("traceID", model.TraceID{High: 0, Low: 1}.String())
id1Search := elastic.NewSearchRequest().
IgnoreUnavailable(true).
Type(spanType).
Source(r.reader.sourceFn(id1Query, model.TimeAsEpochMicroseconds(now.Add(-time.Hour))))
id2Query := elastic.NewTermQuery("traceID", model.TraceID{High: 0, Low:2}.String())
id2Query := elastic.NewTermQuery("traceID", model.TraceID{High: 0, Low: 2}.String())
id2Search := elastic.NewSearchRequest().
IgnoreUnavailable(true).
Type(spanType).
Expand Down Expand Up @@ -266,7 +266,7 @@ func TestSpanReader_multiRead_followUp_query(t *testing.T) {
},
}, nil)

traces, err := r.reader.multiRead(context.Background(), []model.TraceID{{High:0, Low:1}, {High:0, Low:2}}, now, now)
traces, err := r.reader.multiRead(context.Background(), []model.TraceID{{High: 0, Low: 1}, {High: 0, Low: 2}}, now, now)
require.NoError(t, err)
require.NotNil(t, traces)
require.Len(t, traces, 2)
Expand Down Expand Up @@ -826,8 +826,8 @@ func mockSearchService(r *spanReaderTest) *mock.Call {
searchService.On("Aggregation", stringMatcher(operationsAggregation), mock.AnythingOfType("*elastic.TermsAggregation")).Return(searchService)
searchService.On("Aggregation", stringMatcher(traceIDAggregation), mock.AnythingOfType("*elastic.TermsAggregation")).Return(searchService)
r.client.On("Search", mock.AnythingOfType("string"), mock.AnythingOfType("string"), mock.AnythingOfType("string"), mock.AnythingOfType("string"), mock.AnythingOfType("string")).Return(searchService)
return searchService.On("Do", mock.MatchedBy(func(ctx context.Context) bool{
t := reflect.TypeOf(ctx).String()
return searchService.On("Do", mock.MatchedBy(func(ctx context.Context) bool {
t := reflect.TypeOf(ctx).String()
return t == "*context.valueCtx" || t == "*context.emptyCtx"
}))
}
Expand Down
Loading