summaryrefslogtreecommitdiffstats
path: root/modules/csv/csv_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'modules/csv/csv_test.go')
-rw-r--r--modules/csv/csv_test.go21
1 files changed, 11 insertions, 10 deletions
diff --git a/modules/csv/csv_test.go b/modules/csv/csv_test.go
index f6e782a5a4..6ed6986629 100644
--- a/modules/csv/csv_test.go
+++ b/modules/csv/csv_test.go
@@ -16,6 +16,7 @@ import (
"code.gitea.io/gitea/modules/translation"
"github.com/stretchr/testify/assert"
+ "github.com/stretchr/testify/require"
)
func TestCreateReader(t *testing.T) {
@@ -27,7 +28,7 @@ func decodeSlashes(t *testing.T, s string) string {
s = strings.ReplaceAll(s, "\n", "\\n")
s = strings.ReplaceAll(s, "\"", "\\\"")
decoded, err := strconv.Unquote(`"` + s + `"`)
- assert.NoError(t, err, "unable to decode string")
+ require.NoError(t, err, "unable to decode string")
return decoded
}
@@ -99,10 +100,10 @@ j, ,\x20
for n, c := range cases {
rd, err := CreateReaderAndDetermineDelimiter(nil, strings.NewReader(decodeSlashes(t, c.csv)))
- assert.NoError(t, err, "case %d: should not throw error: %v\n", n, err)
+ require.NoError(t, err, "case %d: should not throw error: %v\n", n, err)
assert.EqualValues(t, c.expectedDelimiter, rd.Comma, "case %d: delimiter should be '%c', got '%c'", n, c.expectedDelimiter, rd.Comma)
rows, err := rd.ReadAll()
- assert.NoError(t, err, "case %d: should not throw error: %v\n", n, err)
+ require.NoError(t, err, "case %d: should not throw error: %v\n", n, err)
assert.EqualValues(t, c.expectedRows, rows, "case %d: rows should be equal", n)
}
}
@@ -115,8 +116,8 @@ func (r *mockReader) Read(buf []byte) (int, error) {
func TestDetermineDelimiterShortBufferError(t *testing.T) {
rd, err := CreateReaderAndDetermineDelimiter(nil, &mockReader{})
- assert.Error(t, err, "CreateReaderAndDetermineDelimiter() should throw an error")
- assert.ErrorIs(t, err, io.ErrShortBuffer)
+ require.Error(t, err, "CreateReaderAndDetermineDelimiter() should throw an error")
+ require.ErrorIs(t, err, io.ErrShortBuffer)
assert.Nil(t, rd, "CSV reader should be mnil")
}
@@ -127,11 +128,11 @@ func TestDetermineDelimiterReadAllError(t *testing.T) {
f g
h|i
jkl`))
- assert.NoError(t, err, "CreateReaderAndDetermineDelimiter() shouldn't throw error")
+ require.NoError(t, err, "CreateReaderAndDetermineDelimiter() shouldn't throw error")
assert.NotNil(t, rd, "CSV reader should not be mnil")
rows, err := rd.ReadAll()
- assert.Error(t, err, "RaadAll() should throw error")
- assert.ErrorIs(t, err, csv.ErrFieldCount)
+ require.Error(t, err, "RaadAll() should throw error")
+ require.ErrorIs(t, err, csv.ErrFieldCount)
assert.Empty(t, rows, "rows should be empty")
}
@@ -580,9 +581,9 @@ func TestFormatError(t *testing.T) {
for n, c := range cases {
message, err := FormatError(c.err, &translation.MockLocale{})
if c.expectsError {
- assert.Error(t, err, "case %d: expected an error to be returned", n)
+ require.Error(t, err, "case %d: expected an error to be returned", n)
} else {
- assert.NoError(t, err, "case %d: no error was expected, got error: %v", n, err)
+ require.NoError(t, err, "case %d: no error was expected, got error: %v", n, err)
assert.EqualValues(t, c.expectedMessage, message, "case %d: messages should be equal, expected '%s' got '%s'", n, c.expectedMessage, message)
}
}