mirror of
https://github.com/AdguardTeam/AdGuardHome.git
synced 2024-12-15 19:31:45 +03:00
89694763f5
Merge in DNS/adguard-home from upd-dnsproxy to master Squashed commit of the following: commit 52365328a4c653b0d3bf6d11d8f66a3bf8e0f402 Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Thu Jun 10 18:49:50 2021 +0300 all: rm debug mod replace commit b29e3cffc5dfa58951a9d819a196e588d26dd887 Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Thu Jun 10 18:46:22 2021 +0300 all: upd dnsproxy, fix test, minor imp
72 lines
1.3 KiB
Go
72 lines
1.3 KiB
Go
package dhcpd
|
|
|
|
import (
|
|
"encoding/json"
|
|
"testing"
|
|
|
|
"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)
|
|
if tc.wantErrMsg == "" {
|
|
assert.NoError(t, err)
|
|
} else {
|
|
require.Error(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.NoError(t, err)
|
|
|
|
assert.Equal(t, want, got.A)
|
|
})
|
|
}
|