mirror of
https://github.com/AdguardTeam/AdGuardHome.git
synced 2024-12-22 14:54:25 +03:00
773f02cf7d
Updates #2946.
Squashed commit of the following:
commit f830c03ddee65f7e86c43baa00a7dcc022091d93
Merge: df6c83d7 327e76cd
Author: Ainar Garipov <A.Garipov@AdGuard.COM>
Date: Tue Apr 13 15:55:58 2021 +0300
Merge branch 'master' into 2946-norm-dhcp-host
commit df6c83d7d117b718110a035216e708d5131bf71c
Author: Ainar Garipov <A.Garipov@AdGuard.COM>
Date: Tue Apr 13 15:49:03 2021 +0300
dhcpd: imp docs
commit 1407e9bd7b7694bd3069349faba3ec9ff5eb468b
Author: Ainar Garipov <A.Garipov@AdGuard.COM>
Date: Tue Apr 13 15:27:38 2021 +0300
dhcpd: normalize client host
71 lines
1.3 KiB
Go
71 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.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)
|
|
})
|
|
}
|