mirror of
https://github.com/AdguardTeam/AdGuardHome.git
synced 2024-12-15 11:22:49 +03:00
2eb21ef409
Merge in DNS/adguard-home from 2653-ra-slaac to master Updates #2653. Squashed commit of the following: commit f261413a58dc813e37cc848606ed490b8c0ac9f3 Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Thu Feb 11 20:37:13 2021 +0300 all: doc changes, rm debug commit 4a8c6e4897579493c1ca242fb8f0f440c3b51a74 Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Thu Feb 11 20:11:46 2021 +0300 dhcpd: do not override ra-slaac settings
70 lines
1.3 KiB
Go
70 lines
1.3 KiB
Go
package dhcpd
|
|
|
|
import (
|
|
"encoding/json"
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
func TestNullBool_UnmarshalText(t *testing.T) {
|
|
testCases := []struct {
|
|
name string
|
|
data []byte
|
|
wantErrMsg string
|
|
want nullBool
|
|
}{{
|
|
name: "empty",
|
|
data: []byte{},
|
|
wantErrMsg: "",
|
|
want: nbNull,
|
|
}, {
|
|
name: "null",
|
|
data: []byte("null"),
|
|
wantErrMsg: "",
|
|
want: nbNull,
|
|
}, {
|
|
name: "true",
|
|
data: []byte("true"),
|
|
wantErrMsg: "",
|
|
want: nbTrue,
|
|
}, {
|
|
name: "false",
|
|
data: []byte("false"),
|
|
wantErrMsg: "",
|
|
want: nbFalse,
|
|
}, {
|
|
name: "invalid",
|
|
data: []byte("flase"),
|
|
wantErrMsg: `invalid nullBool value "flase"`,
|
|
want: nbNull,
|
|
}}
|
|
|
|
for _, tc := range testCases {
|
|
t.Run(tc.name, func(t *testing.T) {
|
|
var got nullBool
|
|
err := got.UnmarshalJSON(tc.data)
|
|
if tc.wantErrMsg == "" {
|
|
assert.Nil(t, err)
|
|
} else {
|
|
require.NotNil(t, err)
|
|
assert.Equal(t, tc.wantErrMsg, err.Error())
|
|
}
|
|
|
|
assert.Equal(t, tc.want, got)
|
|
})
|
|
}
|
|
|
|
t.Run("json", func(t *testing.T) {
|
|
want := nbTrue
|
|
var got struct {
|
|
A nullBool
|
|
}
|
|
|
|
err := json.Unmarshal([]byte(`{"A":true}`), &got)
|
|
require.Nil(t, err)
|
|
assert.Equal(t, want, got.A)
|
|
})
|
|
}
|