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