Enforce new linting rules: errname, errorlint, lll, stylecheck ()

This commit is contained in:
sunboyy 2022-11-09 11:21:11 +07:00 committed by GitHub
parent ec08a5a918
commit 482dd095a6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
16 changed files with 891 additions and 336 deletions

View file

@ -5,7 +5,8 @@ import (
"strings"
)
// ExpectMultiLineString compares two multi-line strings and report the difference
// ExpectMultiLineString compares two multi-line strings and report the
// difference.
func ExpectMultiLineString(expected, actual string) error {
expectedLines := strings.Split(expected, "\n")
actualLines := strings.Split(actual, "\n")
@ -17,14 +18,14 @@ func ExpectMultiLineString(expected, actual string) error {
for i := 0; i < numberOfComparableLines; i++ {
if expectedLines[i] != actualLines[i] {
return fmt.Errorf("On line %d\nExpected: %v\nReceived: %v", i+1, expectedLines[i], actualLines[i])
return fmt.Errorf("at line %d\nexpected: %v\nreceived: %v", i+1, expectedLines[i], actualLines[i])
}
}
if len(expectedLines) < len(actualLines) {
return fmt.Errorf("Unexpected lines:\n%s", strings.Join(actualLines[len(expectedLines):], "\n"))
return fmt.Errorf("unexpected lines:\n%s", strings.Join(actualLines[len(expectedLines):], "\n"))
} else if len(expectedLines) > len(actualLines) {
return fmt.Errorf("Missing lines:\n%s", strings.Join(expectedLines[len(actualLines):], "\n"))
return fmt.Errorf("missing lines:\n%s", strings.Join(expectedLines[len(actualLines):], "\n"))
}
return nil

View file

@ -28,9 +28,9 @@ How are you?`
err := testutils.ExpectMultiLineString(expectedText, actualText)
expectedError := "On line 2\nExpected: this is an expected text\nReceived: this is a real text"
expectedError := "at line 2\nexpected: this is an expected text\nreceived: this is a real text"
if err == nil || err.Error() != expectedError {
t.Errorf("Expected = %s\nReceived = %s", expectedError, err.Error())
t.Errorf("expected = %s\nreceived = %s", expectedError, err.Error())
}
})
@ -46,9 +46,9 @@ how are you?`
err := testutils.ExpectMultiLineString(expectedText, actualText)
expectedError := "Missing lines:\nI'm fine...\nThank you..."
expectedError := "missing lines:\nI'm fine...\nThank you..."
if err == nil || err.Error() != expectedError {
t.Errorf("Expected = %s\nReceived = %s", expectedError, err.Error())
t.Errorf("expected = %s\nreceived = %s", expectedError, err.Error())
}
})
@ -64,9 +64,9 @@ Thank you...`
err := testutils.ExpectMultiLineString(expectedText, actualText)
expectedError := "Unexpected lines:\nI'm fine...\nThank you..."
expectedError := "unexpected lines:\nI'm fine...\nThank you..."
if err == nil || err.Error() != expectedError {
t.Errorf("Expected = %s\nReceived = %s", expectedError, err.Error())
t.Errorf("expected = %s\nreceived = %s", expectedError, err.Error())
}
})
}