From 3ba70a27c6ab866a81e4cc72dc886e84644aca1e Mon Sep 17 00:00:00 2001 From: Chris Crone Date: Tue, 4 Aug 2020 13:53:54 +0200 Subject: [PATCH] formatter,multierror,progress: Move to gotest.tools Signed-off-by: Chris Crone --- formatter/units_test.go | 17 +++++++++-------- multierror/multierror_test.go | 19 ++++++++++--------- progress/tty_test.go | 18 +++++++++--------- 3 files changed, 28 insertions(+), 26 deletions(-) diff --git a/formatter/units_test.go b/formatter/units_test.go index 700bc3c40..2c9a22ada 100644 --- a/formatter/units_test.go +++ b/formatter/units_test.go @@ -19,7 +19,8 @@ package formatter import ( "testing" - "github.com/stretchr/testify/assert" + "gotest.tools/v3/assert" + "gotest.tools/v3/assert/cmp" ) const ( @@ -31,29 +32,29 @@ const ( func TestMemBytes(t *testing.T) { var m MemBytes - assert.Nil(t, m.Set("42")) + assert.Assert(t, cmp.Nil(m.Set("42"))) assert.Equal(t, int64(42), m.Value()) assert.Equal(t, "42B", m.String()) - assert.Nil(t, m.Set("1b")) + assert.Assert(t, cmp.Nil(m.Set("1b"))) assert.Equal(t, int64(1), m.Value()) assert.Equal(t, "1B", m.String()) - assert.Nil(t, m.Set("1k")) + assert.Assert(t, cmp.Nil(m.Set("1k"))) assert.Equal(t, int64(kb), m.Value()) assert.Equal(t, "1KiB", m.String()) - assert.Nil(t, m.Set("1m")) + assert.Assert(t, cmp.Nil(m.Set("1m"))) assert.Equal(t, int64(mb), m.Value()) assert.Equal(t, "1MiB", m.String()) - assert.Nil(t, m.Set("1g")) + assert.Assert(t, cmp.Nil(m.Set("1g"))) assert.Equal(t, int64(gb), m.Value()) assert.Equal(t, "1GiB", m.String()) - assert.Nil(t, m.Set("42g")) + assert.Assert(t, cmp.Nil(m.Set("42g"))) assert.Equal(t, int64(42*gb), m.Value()) assert.Equal(t, "42GiB", m.String()) - assert.Error(t, m.Set("###")) + assert.Error(t, m.Set("###"), "invalid size: '###'") } diff --git a/multierror/multierror_test.go b/multierror/multierror_test.go index fdde2f445..c1e097670 100644 --- a/multierror/multierror_test.go +++ b/multierror/multierror_test.go @@ -20,19 +20,20 @@ import ( "errors" "testing" - "github.com/stretchr/testify/assert" + "gotest.tools/v3/assert" + "gotest.tools/v3/assert/cmp" ) func TestSingleError(t *testing.T) { var err *Error err = Append(err, errors.New("error")) - assert.Equal(t, 1, len(err.WrappedErrors())) + assert.Assert(t, cmp.Len(err.WrappedErrors(), 1)) } func TestGoError(t *testing.T) { var err error result := Append(err, errors.New("error")) - assert.Equal(t, 1, len(result.WrappedErrors())) + assert.Assert(t, cmp.Len(result.WrappedErrors(), 1)) } func TestMultiError(t *testing.T) { @@ -41,24 +42,24 @@ func TestMultiError(t *testing.T) { errors.New("first"), errors.New("second"), ) - assert.Equal(t, 2, len(err.WrappedErrors())) - assert.Equal(t, "Error: first\nError: second", err.Error()) + assert.Assert(t, cmp.Len(err.WrappedErrors(), 2)) + assert.Error(t, err, "Error: first\nError: second") } func TestUnwrap(t *testing.T) { var err *Error - assert.Equal(t, nil, errors.Unwrap(err)) + assert.NilError(t, errors.Unwrap(err)) err = Append(err, errors.New("first")) e := errors.Unwrap(err) - assert.Equal(t, "first", e.Error()) + assert.Error(t, e, "first") } func TestErrorOrNil(t *testing.T) { var err *Error - assert.Equal(t, nil, err.ErrorOrNil()) + assert.NilError(t, err.ErrorOrNil()) err = Append(err, errors.New("error")) e := err.ErrorOrNil() - assert.Equal(t, "error", e.Error()) + assert.Error(t, e, "error") } diff --git a/progress/tty_test.go b/progress/tty_test.go index eac286dbf..578a3f414 100644 --- a/progress/tty_test.go +++ b/progress/tty_test.go @@ -22,7 +22,7 @@ import ( "testing" "time" - "github.com/stretchr/testify/assert" + "gotest.tools/v3/assert" ) func TestLineText(t *testing.T) { @@ -42,18 +42,18 @@ func TestLineText(t *testing.T) { lineWidth := len(fmt.Sprintf("%s %s", ev.ID, ev.Text)) out := lineText(ev, 50, lineWidth, true) - assert.Equal(t, "\x1b[37m . id Text Status 0.0s\n\x1b[0m", out) + assert.Equal(t, out, "\x1b[37m . id Text Status 0.0s\n\x1b[0m") out = lineText(ev, 50, lineWidth, false) - assert.Equal(t, " . id Text Status 0.0s\n", out) + assert.Equal(t, out, " . id Text Status 0.0s\n") ev.Status = Done out = lineText(ev, 50, lineWidth, true) - assert.Equal(t, "\x1b[34m . id Text Status 0.0s\n\x1b[0m", out) + assert.Equal(t, out, "\x1b[34m . id Text Status 0.0s\n\x1b[0m") ev.Status = Error out = lineText(ev, 50, lineWidth, true) - assert.Equal(t, "\x1b[31m . id Text Status 0.0s\n\x1b[0m", out) + assert.Equal(t, out, "\x1b[31m . id Text Status 0.0s\n\x1b[0m") } func TestErrorEvent(t *testing.T) { @@ -74,13 +74,13 @@ func TestErrorEvent(t *testing.T) { // Fire "Working" event and check end time isn't touched w.Event(e) event, ok := w.events[e.ID] - assert.True(t, ok) - assert.True(t, event.endTime.Equal(time.Time{})) + assert.Assert(t, ok) + assert.Assert(t, event.endTime.Equal(time.Time{})) // Fire "Error" event and check end time is set e.Status = Error w.Event(e) event, ok = w.events[e.ID] - assert.True(t, ok) - assert.True(t, event.endTime.After(time.Now().Add(-10*time.Second))) + assert.Assert(t, ok) + assert.Assert(t, event.endTime.After(time.Now().Add(-10*time.Second))) }