util/mak: deprecate NonNil, add type-safe NonNilSliceForJSON, NonNilMapForJSON
And put the rationale in the name too to save the callers the need for a comment. Change-Id: I090f51b749a5a0641897ee89a8fb2e2080c8b782 Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
This commit is contained in:

committed by
Maisem Ali

parent
e7376aca25
commit
f3ce1e2536
@ -69,3 +69,21 @@ func TestNonNil(t *testing.T) {
|
||||
t.Error("map still nil")
|
||||
}
|
||||
}
|
||||
|
||||
func TestNonNilMapForJSON(t *testing.T) {
|
||||
type M map[string]int
|
||||
var m M
|
||||
NonNilMapForJSON(&m)
|
||||
if m == nil {
|
||||
t.Fatal("still nil")
|
||||
}
|
||||
}
|
||||
|
||||
func TestNonNilSliceForJSON(t *testing.T) {
|
||||
type S []int
|
||||
var s S
|
||||
NonNilSliceForJSON(&s)
|
||||
if s == nil {
|
||||
t.Fatal("still nil")
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user