Skip to content

Commit

Permalink
test: use standard library testing package
Browse files Browse the repository at this point in the history
  • Loading branch information
mark-rushakoff committed Oct 23, 2024
1 parent cf20016 commit a078c39
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 18 deletions.
4 changes: 0 additions & 4 deletions log/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,16 @@ require (
github.com/bytedance/sonic v1.12.3
github.com/pkg/errors v0.9.1
github.com/rs/zerolog v1.33.0
github.com/stretchr/testify v1.8.1
)

require (
github.com/bytedance/sonic/loader v0.2.0 // indirect
github.com/cloudwego/base64x v0.1.4 // indirect
github.com/cloudwego/iasm v0.2.0 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/klauspost/cpuid/v2 v2.0.9 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/twitchyliquid64/golang-asm v0.15.1 // indirect
golang.org/x/arch v0.0.0-20210923205945-b76863e36670 // indirect
golang.org/x/sys v0.22.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
1 change: 0 additions & 1 deletion log/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.12.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.22.0 h1:RI27ohtqKCnwULzJLqkv897zojh5/DwS/ENaMzUOaWI=
golang.org/x/sys v0.22.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
Expand Down
41 changes: 28 additions & 13 deletions log/slog/logger_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"testing"

"cosmossdk.io/log/slog"
"github.com/stretchr/testify/require"
)

func TestSlog(t *testing.T) {
Expand All @@ -26,37 +25,53 @@ func TestSlog(t *testing.T) {
var line logLine

logger.Debug("Message one", "num", 1)
require.NoError(t, json.Unmarshal(buf.Bytes(), &line))
require.Equal(t, logLine{
if err := json.Unmarshal(buf.Bytes(), &line); err != nil {
t.Fatal(err)
}
if want := (logLine{
Level: stdslog.LevelDebug.String(),
Msg: "Message one",
Num: 1,
}, line)
}); want != line {
t.Fatalf("unexpected log record: want %v, got %v", want, line)
}

buf.Reset()
logger.Info("Message two", "num", 2)
require.NoError(t, json.Unmarshal(buf.Bytes(), &line))
require.Equal(t, logLine{
if err := json.Unmarshal(buf.Bytes(), &line); err != nil {
t.Fatal(err)
}
if want := (logLine{
Level: stdslog.LevelInfo.String(),
Msg: "Message two",
Num: 2,
}, line)
}); want != line {
t.Fatalf("unexpected log record: want %v, got %v", want, line)
}

buf.Reset()
logger.Warn("Message three", "num", 3)
require.NoError(t, json.Unmarshal(buf.Bytes(), &line))
require.Equal(t, logLine{
if err := json.Unmarshal(buf.Bytes(), &line); err != nil {
t.Fatal(err)
}
if want := (logLine{
Level: stdslog.LevelWarn.String(),
Msg: "Message three",
Num: 3,
}, line)
}); want != line {
t.Fatalf("unexpected log record: want %v, got %v", want, line)
}

buf.Reset()
logger.Error("Message four", "num", 4)
require.NoError(t, json.Unmarshal(buf.Bytes(), &line))
require.Equal(t, logLine{
if err := json.Unmarshal(buf.Bytes(), &line); err != nil {
t.Fatal(err)
}
if want := (logLine{
Level: stdslog.LevelError.String(),
Msg: "Message four",
Num: 4,
}, line)
}); want != line {
t.Fatalf("unexpected log record: want %v, got %v", want, line)
}
}

0 comments on commit a078c39

Please sign in to comment.