Skip to content

Commit

Permalink
Improve test messages
Browse files Browse the repository at this point in the history
  • Loading branch information
akiomik committed Aug 6, 2022
1 parent 0b5459e commit f6e8e61
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 23 deletions.
2 changes: 1 addition & 1 deletion config/version_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,6 @@ func TestVersion(t *testing.T) {
// from https://semver.org/#is-there-a-suggested-regular-expression-regex-to-check-a-semver-string
r := regexp.MustCompile(`^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-((?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?$`)
if !r.MatchString(Version) {
t.Errorf("Expect Version to match semver, but it does not")
t.Errorf("Expect to match semver, but it does not")
}
}
8 changes: 4 additions & 4 deletions export/csv_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ func TestExportCsvEmpty(t *testing.T) {
reader := csv.NewReader(f)
_, err = reader.Read()
if err != io.EOF {
t.Errorf("Expect ExportCsv() to create an empty csv file, but not empty: %v", err)
t.Errorf("Expect to create an empty csv file, got %v", err)
return
}
}
Expand Down Expand Up @@ -159,7 +159,7 @@ func TestExportCsvNonEmpty(t *testing.T) {

expectedHeader := []string{"id", "username", "created_at", "full_text", "retweet_count", "favorite_count", "reply_count", "quote_count", "geo", "coordinates", "lang", "source"}
if !reflect.DeepEqual(actualHeader, expectedHeader) {
t.Errorf("Expect ExportCsv() to write %v as a header, but got %v", expectedHeader, expectedHeader)
t.Errorf("Expect to write %v as a header, got %v", expectedHeader, expectedHeader)
return
}

Expand All @@ -178,14 +178,14 @@ func TestExportCsvNonEmpty(t *testing.T) {
}

if !reflect.DeepEqual(actualRecord, expectedRecord) {
t.Errorf("Expect ExportCsv() to write %v as a record #%d, but got %v", expectedRecord, i, actualRecord)
t.Errorf("Expect to write %v as a record #%d, got %v", expectedRecord, i, actualRecord)
return
}
}

_, err = reader.Read()
if err != io.EOF {
t.Errorf("Expect ExportCsv() to reach EOF, but not EOF: %v", err)
t.Errorf("Expect to reach EOF, got not EOF %v", err)
return
}
}
8 changes: 4 additions & 4 deletions export/helper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ func TestContains(t *testing.T) {
t.Run(name, func(t *testing.T) {
actual := Contains(ss, e.value)
if actual != e.expected {
t.Errorf("Expect Contains(%v, %s) = %v, but got %v", ss, e.value, e.expected, actual)
t.Errorf("Expect %v, got %v", e.expected, actual)
return
}
})
Expand All @@ -73,13 +73,13 @@ func TestKeysOf(t *testing.T) {
ks := KeysOf(m)

if len(ks) != len(m) {
t.Errorf("Expect len(KeysOf()) to be %d, but got %d", len(m), len(ks))
t.Errorf("Expect %d, got %d", len(m), len(ks))
return
}

for k, _ := range m {
if !Contains(ks, k) {
t.Errorf("Expect KeysOf() to include \"%s\", but none", k)
t.Errorf(`Expect to include "%s", but none`, k)
return
}
}
Expand All @@ -106,7 +106,7 @@ func TestReversedKeysOf(t *testing.T) {
actual := ReversedKeysOf(m)

if !reflect.DeepEqual(actual, expected) {
t.Errorf("Expect ReversedKeysOf() = %v, but got %v", expected, actual)
t.Errorf("Expect %v, got %v", expected, actual)
return
}
}
12 changes: 6 additions & 6 deletions twitter/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func TestNewClient(t *testing.T) {
}

if len(c.AuthToken) == 0 {
t.Errorf(`Expect not "", got "%s"`, c.AuthToken)
t.Errorf(`Expect not "", got ""`)
return
}
}
Expand All @@ -54,11 +54,11 @@ func TestRequest(t *testing.T) {
client := c.Request()

if client.Header.Get("User-Agent") != expectedUserAgent {
t.Errorf(`Expect "%v", got "%v"`, expectedUserAgent, client.Header.Get("User-Agent"))
t.Errorf("Expect %v, got %v", expectedUserAgent, client.Header.Get("User-Agent"))
}

if client.Token != expectedAuthToken {
t.Errorf(`Expect "%v", got "%v"`, expectedAuthToken, client.Token)
t.Errorf("Expect %v, got %v", expectedAuthToken, client.Token)
}
}

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

actual, err := c.GetGuestToken()
if err != nil {
t.Errorf("Expect not error objects, got %v", err)
t.Errorf("Expect nil, got %v", err)
return
}

Expand Down Expand Up @@ -132,7 +132,7 @@ func TestSearchWhenWithoutCursor(t *testing.T) {
q := Query{Text: "foo"}
actual, err := c.Search(q, "", "")
if err != nil {
t.Errorf("Expect not error objects, got %v", err)
t.Errorf("Expect nil, got %v", err)
return
}

Expand Down Expand Up @@ -168,7 +168,7 @@ func TestSearchWhenWithCursor(t *testing.T) {
q := Query{Text: "foo"}
actual, err := c.Search(q, "", "scroll:deadbeef")
if err != nil {
t.Errorf("Expect not error objects, got %v", err)
t.Errorf("Expect nil, got %v", err)
return
}

Expand Down
4 changes: 2 additions & 2 deletions twitter/json/adaptive_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ func TestFindCursorWhenReplaceEntryExists(t *testing.T) {
expected := "scroll:foobar"
actual, err := j.FindCursor()
if err != nil {
t.Errorf(`Expect not error object, got "%v"`, err)
t.Errorf("Expect nil, got %v", err)
return
}

Expand Down Expand Up @@ -109,7 +109,7 @@ func TestFindCursorWhenAddEntriesExist(t *testing.T) {
expected := "scroll:foobar"
actual, err := j.FindCursor()
if err != nil {
t.Errorf(`Expect not error object, got "%v"`, err)
t.Errorf("Expect nil, got %v", err)
return
}

Expand Down
12 changes: 6 additions & 6 deletions twitter/json/ruby_date_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func TestString(t *testing.T) {
expected := "Mon Aug 19 02:04:28 +0000 2013"
actual := d.String()
if actual != expected {
t.Errorf("Expect RubyDate#String() = \"%s\", but got \"%s\"", expected, actual)
t.Errorf(`Expect "%s", got "%s"`, expected, actual)
return
}
}
Expand All @@ -42,7 +42,7 @@ func TestIso8601(t *testing.T) {
expected := "2013-08-19T02:04:28+00:00"
actual := d.Iso8601()
if actual != expected {
t.Errorf("Expect RubyDate#Iso8601() = \"%s\", but got \"%s\"", expected, actual)
t.Errorf(`Expect "%s", got "%s"`, expected, actual)
return
}
}
Expand All @@ -69,7 +69,7 @@ func TestEqual(t *testing.T) {
t.Run(name, func(t *testing.T) {
actual := e.this.Equal(e.that)
if actual != e.expected {
t.Errorf("Expect RubyDate#Equal() = %v, but got %v", e.expected, actual)
t.Errorf("Expect %v, got %v", e.expected, actual)
return
}
})
Expand All @@ -84,14 +84,14 @@ func TestUnmarshallWhenSucceeded(t *testing.T) {
schema := new(TestSchema)
err := json.Unmarshal([]byte(jsonString), &schema)
if err != nil {
t.Errorf("Expect Query#Encode() not to return error object, but got \"%v\"", err)
t.Errorf("Expect nil, got %v", err)
return
}

expected := RubyDate(time.Date(2013, 8, 19, 2, 4, 28, 0, time.UTC))
actual := schema.CreatedAt
if !actual.Equal(expected) {
t.Errorf("Expect RubyDate#Unmarshal() = \"%v\", but got \"%v\"", expected, actual)
t.Errorf("Expect %v, got %v", expected, actual)
return
}
}
Expand All @@ -104,7 +104,7 @@ func TestUnmarshallWhenFailed(t *testing.T) {
schema := new(TestSchema)
err := json.Unmarshal([]byte(jsonString), &schema)
if err == nil {
t.Errorf("Expect Query#Encode() to return error object, but got nil")
t.Errorf("Expect error object, got nil")
return
}
}

0 comments on commit f6e8e61

Please sign in to comment.