From: pgxiaolianzi Date: Wed, 7 Feb 2024 07:45:14 +0000 (+0000) Subject: log/slog: add test case for level_test.go X-Git-Tag: go1.23rc1~1228 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=b6ca586181f3f1531c01d51d632b50b2c7c784ba;p=gostls13.git log/slog: add test case for level_test.go adds a test case for the MarshalJSON and MarshalText method of the Level type in the slog package. Change-Id: I3f79f0b46c41252ad9d743e03e34503e19998f3e GitHub-Last-Rev: dab00d4c206ca59fcca7ee8d97ca8cdc9475fdce GitHub-Pull-Request: golang/go#65525 Reviewed-on: https://go-review.googlesource.com/c/go/+/561315 Reviewed-by: Damien Neil LUCI-TryBot-Result: Go LUCI Reviewed-by: David Chase Reviewed-by: Jonathan Amsterdam --- diff --git a/src/log/slog/level_test.go b/src/log/slog/level_test.go index 0b28e71e4c..19adcd8466 100644 --- a/src/log/slog/level_test.go +++ b/src/log/slog/level_test.go @@ -5,6 +5,7 @@ package slog import ( + "bytes" "flag" "strings" "testing" @@ -50,12 +51,16 @@ func TestLevelVar(t *testing.T) { } -func TestMarshalJSON(t *testing.T) { +func TestLevelMarshalJSON(t *testing.T) { want := LevelWarn - 3 + wantData := []byte(`"INFO+1"`) data, err := want.MarshalJSON() if err != nil { t.Fatal(err) } + if !bytes.Equal(data, wantData) { + t.Errorf("got %s, want %s", string(data), string(wantData)) + } var got Level if err := got.UnmarshalJSON(data); err != nil { t.Fatal(err) @@ -67,10 +72,14 @@ func TestMarshalJSON(t *testing.T) { func TestLevelMarshalText(t *testing.T) { want := LevelWarn - 3 + wantData := []byte("INFO+1") data, err := want.MarshalText() if err != nil { t.Fatal(err) } + if !bytes.Equal(data, wantData) { + t.Errorf("got %s, want %s", string(data), string(wantData)) + } var got Level if err := got.UnmarshalText(data); err != nil { t.Fatal(err)