1
0
Fork 0
mirror of https://github.com/Luzifer/rconfig.git synced 2024-11-08 16:00:10 +00:00
rconfig/errors_test.go

38 lines
926 B
Go
Raw Permalink Normal View History

2015-09-08 20:07:40 +00:00
package rconfig
import (
"testing"
"github.com/stretchr/testify/assert"
2015-09-08 20:07:40 +00:00
)
func TestErrors(t *testing.T) {
for test, parsable := range map[string]interface{}{
"use string as default to int": struct {
A int `default:"a"` //revive:disable-line:struct-tag // Intentional error for testing
}{},
"use string as default to float": struct {
2015-09-08 20:07:40 +00:00
A float32 `default:"a"`
}{},
"use string as default to uint": struct {
2015-09-08 20:07:40 +00:00
A uint `default:"a"`
}{},
"use string as default to uint in sub-struct": struct {
2015-09-08 20:07:40 +00:00
B struct {
A uint `default:"a"`
}
}{},
"use string list as default to int slice": struct {
A []int `default:"a,b"`
}{},
} {
assert.Error(t, parse(&parsable, nil), test) //#nosec:G601 // Fine for this test
}
assert.Error(t, parse(struct {
A string `default:"a"`
}{}, nil), "feeding non-pointer to parse")
assert.Error(t, parse("test", nil), "feeding non-pointer string to parse")
}