Skip to content

Commit

Permalink
tests: use stretchr/testify instead of custom check package (#130)
Browse files Browse the repository at this point in the history
  • Loading branch information
mfridman authored Sep 6, 2024
1 parent 2f5079b commit 458bfb4
Show file tree
Hide file tree
Showing 14 changed files with 94 additions and 144 deletions.
4 changes: 4 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,18 @@ require (
github.com/mfridman/buildversion v0.3.0
github.com/muesli/termenv v0.15.2
github.com/olekukonko/tablewriter v0.0.5
github.com/stretchr/testify v1.9.0
)

require (
github.com/aymanbagabas/go-osc52/v2 v2.0.1 // indirect
github.com/charmbracelet/x/ansi v0.2.3 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/lucasb-eyer/go-colorful v1.2.0 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
github.com/mattn/go-runewidth v0.0.16 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/rivo/uniseg v0.4.7 // indirect
golang.org/x/sys v0.25.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
10 changes: 10 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ github.com/charmbracelet/lipgloss v0.13.0 h1:4X3PPeoWEDCMvzDvGmTajSyYPcZM4+y8sCA
github.com/charmbracelet/lipgloss v0.13.0/go.mod h1:nw4zy0SBX/F/eAO1cWdcvy6qnkDUxr8Lw7dvFrAIbbY=
github.com/charmbracelet/x/ansi v0.2.3 h1:VfFN0NUpcjBRd4DnKfRaIRo53KRgey/nhOoEqosGDEY=
github.com/charmbracelet/x/ansi v0.2.3/go.mod h1:dk73KoMTT5AX5BsX0KrqhsTqAnhZZoCBjs7dGWp4Ktw=
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/lucasb-eyer/go-colorful v1.2.0 h1:1nnpGOrhyZZuNyfu1QjKiUICQ74+3FNCN69Aj6K7nkY=
github.com/lucasb-eyer/go-colorful v1.2.0/go.mod h1:R4dSotOR9KMtayYi1e77YzuveK+i7ruzyGqttikkLy0=
github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY=
Expand All @@ -17,9 +19,17 @@ github.com/muesli/termenv v0.15.2 h1:GohcuySI0QmI3wN8Ok9PtKGkgkFIk7y6Vpb5PvrY+Wo
github.com/muesli/termenv v0.15.2/go.mod h1:Epx+iuz8sNs7mNKhxzH4fWXGNpZwUaJKRS1noLXviQ8=
github.com/olekukonko/tablewriter v0.0.5 h1:P2Ga83D34wi1o9J6Wh1mRuqd4mF/x/lgBS7N7AbDhec=
github.com/olekukonko/tablewriter v0.0.5/go.mod h1:hPp6KlRPjbx+hW8ykQs1w3UBbZlj6HuIJcUGPhkA7kY=
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/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc=
github.com/rivo/uniseg v0.4.7 h1:WUdvkW8uEhrYfLC4ZzdpI2ztxP1I582+49Oc5Mq64VQ=
github.com/rivo/uniseg v0.4.7/go.mod h1:FN3SvrM+Zdj16jyLfmOkMNblXMcoc8DfTHruCPUcx88=
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.25.0 h1:r+8e+loiHxRqhXVl6ML1nO3l1+oFoWbnlu2Ehimmi34=
golang.org/x/sys v0.25.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.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
86 changes: 0 additions & 86 deletions internal/check/check.go

This file was deleted.

16 changes: 8 additions & 8 deletions parse/event_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"strings"
"testing"

"github.com/mfridman/tparse/internal/check"
"github.com/stretchr/testify/require"
)

func TestNewEvent(t *testing.T) {
Expand Down Expand Up @@ -99,7 +99,7 @@ func TestNewEvent(t *testing.T) {
for i, tc := range tt {
t.Run(fmt.Sprintf("event_%d", i), func(t *testing.T) {
e, err := NewEvent([]byte(tc.raw))
check.NoError(t, err)
require.NoError(t, err)

if e.Action != tc.action {
t.Errorf("wrong action: got %q, want %q", e.Action, tc.action)
Expand Down Expand Up @@ -166,7 +166,7 @@ func TestCachedEvent(t *testing.T) {
for i, tc := range tt {
t.Run(fmt.Sprintf("event_%d", i), func(t *testing.T) {
e, err := NewEvent([]byte(tc.raw))
check.NoError(t, err)
require.NoError(t, err)

got := e.IsCached()
want := tc.cached
Expand Down Expand Up @@ -220,7 +220,7 @@ func TestCoverEvent(t *testing.T) {
for i, tc := range tt {
t.Run(fmt.Sprintf("event_%d", i), func(t *testing.T) {
e, err := NewEvent([]byte(tc.raw))
check.NoError(t, err)
require.NoError(t, err)

f, ok := e.Cover()
if ok != tc.cover {
Expand Down Expand Up @@ -264,7 +264,7 @@ func TestNoTestFiles(t *testing.T) {
for i, tc := range tt {
t.Run(fmt.Sprintf("event_%d", i), func(t *testing.T) {
e, err := NewEvent([]byte(tc.raw))
check.NoError(t, err)
require.NoError(t, err)

got := e.NoTestFiles()
want := tc.noTestFiles
Expand Down Expand Up @@ -303,7 +303,7 @@ func TestNoTestsToRun(t *testing.T) {
for i, tc := range tt {
t.Run(fmt.Sprintf("event_%d", i), func(t *testing.T) {
e, err := NewEvent([]byte(tc.raw))
check.NoError(t, err)
require.NoError(t, err)

got := e.NoTestsToRun()
want := tc.noTests
Expand Down Expand Up @@ -344,7 +344,7 @@ func TestNoTestsWarn(t *testing.T) {
for i, tc := range tt {
t.Run(fmt.Sprintf("event_%d", i), func(t *testing.T) {
e, err := NewEvent([]byte(tc.raw))
check.NoError(t, err)
require.NoError(t, err)

got := e.NoTestsWarn()
want := tc.wanNoTests
Expand Down Expand Up @@ -394,7 +394,7 @@ func TestDiscardOutput(t *testing.T) {
}
for _, tc := range tt {
e, err := NewEvent([]byte(tc))
check.NoError(t, err)
require.NoError(t, err)
if e.DiscardOutput() != true {
t.Errorf("%s - %s failed discard check: got:%v, want:%v", e.Package, e.Test, e.DiscardOutput(), true)
}
Expand Down
10 changes: 6 additions & 4 deletions tests/cached_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ import (
"path/filepath"
"testing"

"github.com/mfridman/tparse/internal/check"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

"github.com/mfridman/tparse/parse"
)

Expand Down Expand Up @@ -56,11 +58,11 @@ func TestPackageCache(t *testing.T) {
t.Run(tc.fileName, func(t *testing.T) {
inputFile := filepath.Join(base, tc.fileName+".jsonl")
f, err := os.Open(inputFile)
check.NoError(t, err)
require.NoError(t, err)

summary, err := parse.Process(f)
check.NoError(t, err)
check.Number(t, len(summary.Packages), len(tc.expected))
require.NoError(t, err)
assert.Equal(t, len(summary.Packages), len(tc.expected))

for name, pkg := range summary.Packages {
t.Run(name, func(t *testing.T) {
Expand Down
10 changes: 6 additions & 4 deletions tests/cover_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ import (
"path/filepath"
"testing"

"github.com/mfridman/tparse/internal/check"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

"github.com/mfridman/tparse/parse"
)

Expand Down Expand Up @@ -59,11 +61,11 @@ func Test(t *testing.T) {
t.Run(tc.fileName, func(t *testing.T) {
inputFile := filepath.Join(base, tc.fileName+".jsonl")
f, err := os.Open(inputFile)
check.NoError(t, err)
require.NoError(t, err)

summary, err := parse.Process(f)
check.NoError(t, err)
check.Number(t, len(summary.Packages), len(tc.expected))
require.NoError(t, err)
assert.Equal(t, len(summary.Packages), len(tc.expected))

for name, pkg := range summary.Packages {
t.Run(name, func(t *testing.T) {
Expand Down
7 changes: 4 additions & 3 deletions tests/follow_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@ import (
"path/filepath"
"testing"

"github.com/stretchr/testify/assert"

"github.com/mfridman/tparse/internal/app"
"github.com/mfridman/tparse/internal/check"
"github.com/mfridman/tparse/parse"
)

Expand Down Expand Up @@ -46,7 +47,7 @@ func TestFollow(t *testing.T) {
if err != nil && !errors.Is(err, tc.err) {
t.Fatal(err)
}
check.Number(t, gotExitCode, tc.exitCode)
assert.Equal(t, gotExitCode, tc.exitCode)
goldenFile := filepath.Join(base, tc.fileName+".golden")
want, err := os.ReadFile(goldenFile)
if err != nil {
Expand Down Expand Up @@ -80,7 +81,7 @@ func TestFollow(t *testing.T) {
if err != nil && !errors.Is(err, tc.err) {
t.Fatal(err)
}
check.Number(t, gotExitCode, tc.exitCode)
assert.Equal(t, gotExitCode, tc.exitCode)
goldenFile := filepath.Join(base, tc.fileName+".golden")
want, err := os.ReadFile(goldenFile)
if err != nil {
Expand Down
10 changes: 6 additions & 4 deletions tests/outcome_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ import (
"path/filepath"
"testing"

"github.com/mfridman/tparse/internal/check"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

"github.com/mfridman/tparse/parse"
)

Expand Down Expand Up @@ -59,9 +61,9 @@ func TestFinalOutcome(t *testing.T) {
t.Fatal(err)
}
summary, err := parse.Process(f)
check.NoError(t, err)
check.Number(t, len(summary.Packages), len(tc.registry))
check.Number(t, summary.ExitCode(), tc.exitCode)
require.NoError(t, err)
assert.Equal(t, len(summary.Packages), len(tc.registry))
assert.Equal(t, summary.ExitCode(), tc.exitCode)

for name, pkg := range summary.Packages {
want, ok := tc.registry[name]
Expand Down
12 changes: 7 additions & 5 deletions tests/package_start_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ import (
"testing"
"time"

"github.com/mfridman/tparse/internal/check"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

"github.com/mfridman/tparse/parse"
)

Expand All @@ -30,12 +32,12 @@ func TestPackageStartTime(t *testing.T) {

fileName := "./testdata/go120_start_action.jsonl"
f, err := os.Open(fileName)
check.NoError(t, err)
require.NoError(t, err)
defer f.Close()

summary, err := parse.Process(f)
check.NoError(t, err)
check.Number(t, len(summary.Packages), len(expected))
require.NoError(t, err)
assert.Equal(t, len(summary.Packages), len(expected))

for _, p := range summary.Packages {
if p.StartTime.IsZero() {
Expand All @@ -46,7 +48,7 @@ func TestPackageStartTime(t *testing.T) {
t.Fatalf("package %q not found in expected map", p.Summary.Package)
}
want, err := time.Parse(time.RFC3339, unparsed)
check.NoError(t, err)
require.NoError(t, err)
if !p.StartTime.Equal(want) {
t.Fatalf("package %q start time got %q want %q", p.Summary.Package, p.StartTime, want)
}
Expand Down
10 changes: 6 additions & 4 deletions tests/panic_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ import (
"path/filepath"
"testing"

"github.com/mfridman/tparse/internal/check"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

"github.com/mfridman/tparse/parse"
)

Expand Down Expand Up @@ -65,11 +67,11 @@ func TestPanic(t *testing.T) {
for _, tc := range tt {
t.Run(tc.fileName, func(t *testing.T) {
f, err := os.Open(filepath.Join(base, tc.fileName))
check.NoError(t, err)
require.NoError(t, err)

summary, err := parse.Process(f)
check.NoError(t, err)
check.Number(t, summary.ExitCode(), 1)
require.NoError(t, err)
assert.Equal(t, 1, summary.ExitCode())

for name, pkg := range summary.Packages {
want, ok := tc.expected[name]
Expand Down
11 changes: 8 additions & 3 deletions tests/prescan_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ import (
"path/filepath"
"testing"

"github.com/mfridman/tparse/internal/check"
"github.com/stretchr/testify/require"

"github.com/mfridman/tparse/parse"
)

Expand All @@ -31,10 +32,14 @@ func TestPrescan(t *testing.T) {
t.Run(tc.fileName, func(t *testing.T) {
inputFile := filepath.Join(base, tc.fileName)
f, err := os.Open(inputFile)
check.NoError(t, err)
require.NoError(t, err)

_, err = parse.Process(f)
check.IsError(t, err, tc.err)
if tc.err != nil {
require.ErrorIs(t, err, tc.err)
return
}
require.NoError(t, err)
})

}
Expand Down
Loading

0 comments on commit 458bfb4

Please sign in to comment.