-
Notifications
You must be signed in to change notification settings - Fork 0
/
errors_test.go
56 lines (47 loc) · 1.3 KB
/
errors_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
package gsheets
import (
"errors"
"reflect"
"testing"
"github.com/stretchr/testify/assert"
)
func TestConvertError_Error(t *testing.T) {
innerErr := errors.New("inner error")
err := &ConvertError{
CV: "test",
Typ: reflect.Bool,
err: innerErr,
}
assert.Equal(t, `gsheets: conversion error, could not convert value "test" into Go type "bool"`, err.Error())
}
func TestConvertError_Unwrap(t *testing.T) {
expectedErr := errors.New("inner error")
err := &ConvertError{err: expectedErr}
assert.Equal(t, expectedErr, err.Unwrap())
}
func TestInvalidDateTimeFormatError_Error(t *testing.T) {
err := &InvalidDateTimeFormatError{
CV: "2024-12-31",
Formats: []string{"2.1.2006", "1/2/2006"},
}
assert.Equal(t, `gsheets: invalid datetime format in value "2024-12-31", recognized formats are: ["2.1.2006", "1/2/2006"]`, err.Error())
}
func TestMappingError_Error(t *testing.T) {
innerErr := errors.New("inner error")
err := &MappingError{
Sheet: "test",
Cell: "A1",
Field: "Type.Field",
err: innerErr,
}
const msg = `inner error
sheet: "test"
cell: "A1"
field: "Type.Field"`
assert.Equal(t, msg, err.Error())
}
func TestMappingError_Unwrap(t *testing.T) {
expectedErr := errors.New("inner error")
err := &MappingError{err: expectedErr}
assert.Equal(t, expectedErr, err.Unwrap())
}