mirror of
https://github.com/AdguardTeam/AdGuardHome.git
synced 2024-12-17 21:31:43 +03:00
ea8950a80d
Squashed commit of the following: commit 5345a14b3565f358c56a37500cafb35b7e397951 Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Thu Oct 21 21:13:06 2021 +0300 all: fix windows tests commit 8b9cdbe3e78f43339d21277f04e686bb154f6968 Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Thu Oct 21 20:23:55 2021 +0300 all: imp code commit 271fdbe74c29d8ea4b53d7f56d2a36612dfed7b3 Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Thu Oct 21 19:43:32 2021 +0300 all: imp testing commit e340f9d48679c57fc8eb579b8b78d4957be111c4 Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Thu Oct 21 18:53:51 2021 +0300 all: use testutil
67 lines
1.3 KiB
Go
67 lines
1.3 KiB
Go
package dhcpd
|
|
|
|
import (
|
|
"encoding/json"
|
|
"testing"
|
|
|
|
"github.com/AdguardTeam/golibs/testutil"
|
|
"github.com/stretchr/testify/assert"
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
func TestNullBool_UnmarshalJSON(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)
|
|
testutil.AssertErrorMsg(t, tc.wantErrMsg, err)
|
|
|
|
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.NoError(t, err)
|
|
|
|
assert.Equal(t, want, got.A)
|
|
})
|
|
}
|