mirror of
https://github.com/tailscale/tailscale.git
synced 2025-05-05 23:21:00 +00:00
types/opt: fix test to be agnostic to omitzero support (#14401)
The omitzero tag option has been backported to v1 "encoding/json" from the "encoding/json/v2" prototype and will land in Go1.24. Until we fully upgrade to Go1.24, adjust the test to be agnostic to which version of Go someone is using. Updates tailscale/corp#25406 Signed-off-by: Joe Tsai <joetsai@digital-static.net>
This commit is contained in:
parent
cc168d9f6b
commit
5883ca72a7
@ -9,6 +9,8 @@ import (
|
|||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
jsonv2 "github.com/go-json-experiment/json"
|
jsonv2 "github.com/go-json-experiment/json"
|
||||||
|
"tailscale.com/types/bools"
|
||||||
|
"tailscale.com/util/must"
|
||||||
)
|
)
|
||||||
|
|
||||||
type testStruct struct {
|
type testStruct struct {
|
||||||
@ -87,7 +89,14 @@ func TestValue(t *testing.T) {
|
|||||||
False: ValueOf(false),
|
False: ValueOf(false),
|
||||||
ExplicitUnset: Value[bool]{},
|
ExplicitUnset: Value[bool]{},
|
||||||
},
|
},
|
||||||
want: `{"True":true,"False":false,"Unset":null,"ExplicitUnset":null}`,
|
want: bools.IfElse(
|
||||||
|
// Detect whether v1 "encoding/json" supports `omitzero` or not.
|
||||||
|
// TODO(Go1.24): Remove this after `omitzero` is supported.
|
||||||
|
string(must.Get(json.Marshal(struct {
|
||||||
|
X int `json:",omitzero"`
|
||||||
|
}{}))) == `{}`,
|
||||||
|
`{"True":true,"False":false}`, // omitzero supported
|
||||||
|
`{"True":true,"False":false,"Unset":null,"ExplicitUnset":null}`), // omitzero not supported
|
||||||
wantBack: struct {
|
wantBack: struct {
|
||||||
True Value[bool] `json:",omitzero"`
|
True Value[bool] `json:",omitzero"`
|
||||||
False Value[bool] `json:",omitzero"`
|
False Value[bool] `json:",omitzero"`
|
||||||
|
Loading…
x
Reference in New Issue
Block a user