Files
config/value/string_test.go
andrey f9a0411192
All checks were successful
Go Action / goaction (push) Successful in 29s
def (#12)
Reviewed-on: #12
2025-12-26 14:55:42 +03:00

35 lines
794 B
Go

package value_test
import (
"encoding/json"
"testing"
"gitoa.ru/go-4devs/config"
"gitoa.ru/go-4devs/config/test/require"
"gitoa.ru/go-4devs/config/value"
)
func TestStringUnmarshal(t *testing.T) {
t.Parallel()
st := value.String("test")
data, err := json.Marshal([]string{"test1", "test2"})
require.NoError(t, err)
sta := value.JBytes(data)
ac := ""
require.NoError(t, st.Unmarshal(&ac))
require.Equal(t, "test", ac)
aca := []string{}
require.NoError(t, sta.Unmarshal(&aca))
require.Equal(t, []string{"test1", "test2"}, aca)
require.ErrorIs(t, sta.Unmarshal(ac), config.ErrWrongType)
require.ErrorIs(t, sta.Unmarshal(&ac), config.ErrWrongType)
require.ErrorIs(t, st.Unmarshal(aca), config.ErrWrongType)
require.ErrorIs(t, st.Unmarshal(&aca), config.ErrWrongType)
}