Skip to content

Commit

Permalink
Using require.Contains instead of require.Equal for some tests
Browse files Browse the repository at this point in the history
Signed-off-by: Ashmita Bohara <ashmita.bohara152@gmail.com>
  • Loading branch information
Ashmita152 committed Nov 17, 2020
1 parent d75c23c commit b4db0aa
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 5 deletions.
2 changes: 1 addition & 1 deletion cmd/anonymizer/app/uiconv/extractor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ func TestExtractor_TraceOutputFileError(t *testing.T) {
reader,
zap.NewNop(),
)
require.Equal(t, "cannot create output file: open fixtures/trace_success_ui_anonymized.json: permission denied", err.Error())
require.Contains(t, err.Error(), "cannot create output file")
}

func TestExtractor_TraceScanError(t *testing.T) {
Expand Down
6 changes: 4 additions & 2 deletions cmd/anonymizer/app/uiconv/module_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@ func TestModule_TraceNonExistent(t *testing.T) {
TraceID: "2be38093ead7a083",
}
err := Extract(config, zap.NewNop())
require.Equal(t, "cannot open captured file: open fixtures/trace_non_existent.json: no such file or directory", err.Error())
require.Contains(t, err.Error(), "cannot open captured file")
require.Contains(t, err.Error(), "no such file or directory")
}

func TestModule_TraceOutputFileError(t *testing.T) {
Expand All @@ -76,5 +77,6 @@ func TestModule_TraceOutputFileError(t *testing.T) {
defer os.Chmod("fixtures", 0755)

err = Extract(config, zap.NewNop())
require.Equal(t, "cannot create output file: open fixtures/trace_success_ui_anonymized.json: permission denied", err.Error())
require.Contains(t, err.Error(), "cannot create output file")
require.Contains(t, err.Error(), "permission denied")
}
5 changes: 3 additions & 2 deletions cmd/anonymizer/app/uiconv/reader_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ func TestReader_TraceNonExistent(t *testing.T) {
inputFile,
zap.NewNop(),
)
require.Equal(t, "cannot open captured file: open fixtures/trace_non_existent.json: no such file or directory", err.Error())
require.Contains(t, err.Error(), "cannot open captured file")
require.Contains(t, err.Error(), "no such file or directory")
}

func TestReader_TraceEmpty(t *testing.T) {
Expand Down Expand Up @@ -95,7 +96,7 @@ func TestReader_TraceInvalidJson(t *testing.T) {
require.NoError(t, err)

_, err = r.NextSpan()
require.Equal(t, "cannot unmarshal span: json: cannot unmarshal string into Go struct field Span.duration of type uint64; {\"traceID\":\"2be38093ead7a083\",\"spanID\":\"7bd66f09ba90ea3d\",\"duration\": \"invalid\"}\n", err.Error())
require.Contains(t, err.Error(), "cannot unmarshal span: json: cannot unmarshal string into Go struct field Span.duration of type uint64")
assert.Equal(t, 0, r.spansRead)
assert.Equal(t, true, r.eofReached)
}

0 comments on commit b4db0aa

Please sign in to comment.