Skip to content

Commit

Permalink
change test library
Browse files Browse the repository at this point in the history
  • Loading branch information
dropwhile committed May 29, 2021
1 parent 733a3d4 commit adec454
Show file tree
Hide file tree
Showing 9 changed files with 50 additions and 40 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ Changelog

## HEAD

## 1.0.4 2021-05-28
* change test only dependency (test helper functions)

## 1.0.3 2019-09-22
* Bump some dependencies

Expand Down
7 changes: 4 additions & 3 deletions formatwriter_json_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ import (
"encoding/json"
"testing"

"github.com/stretchr/testify/assert"
"gotest.tools/v3/assert"
is "gotest.tools/v3/assert/cmp"
)

func testEncodeString(e byteSliceWriter, s string) {
Expand All @@ -31,12 +32,12 @@ func TestFormatWriterJSONEncodeString(t *testing.T) {
b := &bytes.Buffer{}
for name, s := range jsonStringTests {
e, err := json.Marshal(s)
assert.Nil(t, err, "%s: json marshal failed", name)
assert.Check(t, err, "%s: json marshal failed", name)

b.Truncate(0)
b.WriteByte('"')
encodeStringJSON(b, s)
b.WriteByte('"')
assert.Equal(t, string(e), b.String(), "%s: did not match expectation", name)
assert.Check(t, is.Equal(string(e), b.String()), "%s: did not match expectation", name)
}
}
5 changes: 3 additions & 2 deletions formatwriter_plain_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ import (
"bytes"
"testing"

"github.com/stretchr/testify/assert"
"gotest.tools/v3/assert"
is "gotest.tools/v3/assert/cmp"
)

func TestFormatWriterPlainEncodeString(t *testing.T) {
Expand All @@ -29,6 +30,6 @@ func TestFormatWriterPlainEncodeString(t *testing.T) {
for name, tt := range stringTests {
b.Truncate(0)
encodeStringPlain(b, tt.input)
assert.Equal(t, []byte(tt.output), b.Bytes(), "%s: did not match expectation", name)
assert.Check(t, is.DeepEqual([]byte(tt.output), b.Bytes()), "%s: did not match expectation", name)
}
}
5 changes: 3 additions & 2 deletions formatwriter_structured_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ import (
"bytes"
"testing"

"github.com/stretchr/testify/assert"
"gotest.tools/v3/assert"
is "gotest.tools/v3/assert/cmp"
)

func TestFormatWriterStructuredEncodeString(t *testing.T) {
Expand All @@ -29,6 +30,6 @@ func TestFormatWriterStructuredEncodeString(t *testing.T) {
for name, tt := range stringTests {
b.Truncate(0)
encodeStringStructured(b, tt.input)
assert.Equal(t, []byte(tt.output), b.Bytes(), "%s: did not match expectation", name)
assert.Check(t, is.DeepEqual([]byte(tt.output), b.Bytes()), "%s: did not match expectation", name)
}
}
5 changes: 2 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ module github.com/cactus/mlog
go 1.12

require (
github.com/cactus/tai64 v1.0.0
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/stretchr/testify v1.4.0
github.com/cactus/tai64 v1.0.1
gotest.tools/v3 v3.0.3
)
33 changes: 17 additions & 16 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
github.com/cactus/tai64 v1.0.0 h1:2G/693el0FjkhychJt8iBkCXa9OOxcs5Py5+6v3gypw=
github.com/cactus/tai64 v1.0.0/go.mod h1:WhJw2EH0VDwR0Rzw4h03HV7pLkJIOJPXXs+gNx8eYz8=
github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/stretchr/objx v0.1.0 h1:4G4v2dO3VZwixGIRoQ5Lfboy6nUhCyYzaqnIAPPhYs4=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.4.0 h1:2E4SXV/wtOkTonXsotYi4li6zVWxYlZuYNCXe9XRJyk=
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
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.v2 v2.2.2 h1:ZCJp+EgiOT7lHqUV2J862kp8Qj64Jo6az82+3Td9dZw=
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
github.com/cactus/tai64 v1.0.1 h1:rXBf2Ab+1F8Fr9wAtB3xilSnDsHwfpeJUKgham4Bot0=
github.com/cactus/tai64 v1.0.1/go.mod h1:gu5LAXd6eWwrRD/HPw+aTrJF5WkieYswRVLSNslKGg4=
github.com/google/go-cmp v0.4.0 h1:xsAVV57WRhGj6kEIi8ReJzQlHHqcBYCElAvkovg3B/4=
github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/pkg/errors v0.8.1 h1:iURUrRGxPUNPdy5/HRSm+Yj6okJ6UtLINN0Q9M4+h3I=
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/spf13/pflag v1.0.3/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/tools v0.0.0-20190624222133-a101b041ded4/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
gotest.tools/v3 v3.0.3 h1:4AuOwCGf4lLR9u3YOe2awrHygurzhO/HeQ6laiA6Sx0=
gotest.tools/v3 v3.0.3/go.mod h1:Z7Lb0S5l+klDB31fvDQX8ss/FlKDxtlFlw3Oa8Ymbl8=
20 changes: 11 additions & 9 deletions logger_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ import (
"testing"
"time"

"github.com/stretchr/testify/assert"
"gotest.tools/v3/assert"
is "gotest.tools/v3/assert/cmp"
"gotest.tools/v3/assert/opt"
)

var update = flag.Bool("update", false, "update golden files")
Expand Down Expand Up @@ -94,7 +96,7 @@ func TestLoggerMsgs(t *testing.T) {
ioutil.WriteFile(golden, actual, 0644)
}
expected, _ := ioutil.ReadFile(golden)
assert.Equal(t, string(expected), string(actual), "%s: did not match expectation", name)
assert.Check(t, is.Equal(string(expected), string(actual)), "%s: did not match expectation", name)
}

}
Expand All @@ -108,8 +110,8 @@ func TestLoggerTimestamp(t *testing.T) {
logger.Info("test this")
ts := bytes.Split(buf.Bytes()[6:], []byte{'"'})[0]
tlog, err := time.Parse(time.RFC3339Nano, string(ts))
assert.Nil(t, err, "Failed to parse time from log")
assert.WithinDuration(t, tnow, tlog, 2*time.Second, "Time not even close")
assert.Check(t, err, "Failed to parse time from log")
assert.Assert(t, is.DeepEqual(tnow, tlog, opt.TimeWithThreshold(2*time.Second)), "Time not even close")

buf.Truncate(0)

Expand All @@ -119,8 +121,8 @@ func TestLoggerTimestamp(t *testing.T) {
logger.Info("test this")
ts = bytes.Split(buf.Bytes()[6:], []byte{'"'})[0]
tlog, err = time.Parse(time.RFC3339Nano, string(ts))
assert.Nil(t, err, "Failed to parse time from log")
assert.WithinDuration(t, tnow, tlog, 2*time.Second, "Time not even close")
assert.Check(t, err, "Failed to parse time from log")
assert.Assert(t, is.DeepEqual(tnow, tlog, opt.TimeWithThreshold(2*time.Second)), "Time not even close")

buf.Truncate(0)

Expand All @@ -130,8 +132,8 @@ func TestLoggerTimestamp(t *testing.T) {
logger.Info("test this")
ts = bytes.Split(buf.Bytes()[6:], []byte{'"'})[0]
tlog, err = time.Parse(time.RFC3339Nano, string(ts))
assert.Nil(t, err, "Failed to parse time from log")
assert.WithinDuration(t, tnow, tlog, 2*time.Second, "Time not even close")
assert.Check(t, err, "Failed to parse time from log")
assert.Assert(t, is.DeepEqual(tnow, tlog, opt.TimeWithThreshold(2*time.Second)), "Time not even close")
}

func TestPanics(t *testing.T) {
Expand Down Expand Up @@ -183,6 +185,6 @@ func TestPanics(t *testing.T) {
ioutil.WriteFile(golden, actual, 0644)
}
expected, _ := ioutil.ReadFile(golden)
assert.Equal(t, string(expected), string(actual), "%s: did not match expectation", name)
assert.Check(t, is.Equal(string(expected), string(actual)), "%s: did not match expectation", name)
}
}
5 changes: 3 additions & 2 deletions logmap_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ package mlog
import (
"testing"

"github.com/stretchr/testify/assert"
"gotest.tools/v3/assert"
is "gotest.tools/v3/assert/cmp"
)

type discardSliceWriter struct{}
Expand Down Expand Up @@ -45,6 +46,6 @@ func TestLogMapWriteTo(t *testing.T) {
m.sortedWriteBuf(buf)
n := `test="this is \"a test\" of \t some \n a"`
l := buf.String()
assert.Equal(t, n, l, "did not match")
assert.Check(t, is.Equal(n, l), "did not match")

}
7 changes: 4 additions & 3 deletions time_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ import (
"testing"
"time"

"github.com/stretchr/testify/assert"
"gotest.tools/v3/assert"
is "gotest.tools/v3/assert/cmp"
)

func TestTime(t *testing.T) {
Expand Down Expand Up @@ -40,7 +41,7 @@ func TestTime(t *testing.T) {
for _, tc := range cases {
b.Truncate(0)
writeTime(b, &(tc.T), tc.F)
assert.Equal(t, tc.R, b.String(), "time written incorrectly")
assert.Check(t, is.Equal(tc.R, b.String()), "time written incorrectly")
}
}

Expand Down Expand Up @@ -77,6 +78,6 @@ func TestTimeTAI64N(t *testing.T) {
for _, tc := range cases {
b.Truncate(0)
writeTimeTAI64N(b, &(tc.T), tc.F)
assert.Equal(t, tc.R, b.String(), "time written incorrectly")
assert.Check(t, is.Equal(tc.R, b.String()), "time written incorrectly")
}
}

0 comments on commit adec454

Please sign in to comment.