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

Fix error equals #2429

Merged
merged 2 commits into from
Aug 28, 2020
Merged
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
11 changes: 8 additions & 3 deletions cmd/query/app/query_parser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,15 @@
package app

import (
"fmt"
"net/http"
"regexp"
"testing"
"time"

"github.com/kr/pretty"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

"github.com/jaegertracing/jaeger/model"
"github.com/jaegertracing/jaeger/storage/spanstore"
Expand All @@ -41,8 +44,8 @@ func TestParseTraceQuery(t *testing.T) {
{"x?service=service&start=string", errParseInt, nil},
{"x?service=service&end=string", errParseInt, nil},
{"x?service=service&limit=string", errParseInt, nil},
{"x?service=service&start=0&end=0&operation=operation&limit=200&minDuration=20", "cannot not parse minDuration: time: missing unit in duration 20", nil},
{"x?service=service&start=0&end=0&operation=operation&limit=200&minDuration=20s&maxDuration=30", "cannot not parse maxDuration: time: missing unit in duration 30", nil},
{"x?service=service&start=0&end=0&operation=operation&limit=200&minDuration=20", `cannot not parse minDuration: time: missing unit in duration "?20"?$`, nil},
{"x?service=service&start=0&end=0&operation=operation&limit=200&minDuration=20s&maxDuration=30", `cannot not parse maxDuration: time: missing unit in duration "?30"?$`, nil},
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Personally, having been burnt by the changing stdlib error messages in the past, I now try to write tests that only check for a substring or a prefix of the error which is stable and comes from our code, such as cannot not parse minDuration.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup, I would agree with that. Or, alternatively, wrap the error into a custom error type and assert on the type rather than error string comparisons.

{"x?service=service&start=0&end=0&operation=operation&limit=200&tag=k:v&tag=x:y&tag=k&log=k:v&log=k", `malformed 'tag' parameter, expecting key:value, received: k`, nil},
{"x?service=service&start=0&end=0&operation=operation&limit=200&minDuration=25s&maxDuration=1s", `'maxDuration' should be greater than 'minDuration'`, nil},
{"x?service=service&start=0&end=0&operation=operation&limit=200&tag=k:v&tag=x:y", noErr,
Expand Down Expand Up @@ -161,7 +164,9 @@ func TestParseTraceQuery(t *testing.T) {
}
}
} else {
assert.EqualError(t, err, test.errMsg)
matched, matcherr := regexp.MatchString(test.errMsg, err.Error())
require.NoError(t, matcherr)
assert.True(t, matched, fmt.Sprintf("Error \"%s\" should match \"%s\"", err.Error(), test.errMsg))
}
})
}
Expand Down