mirror of https://github.com/docker/compose.git
Merge pull request #419 from docker/test-frameworks
Move formatter, multierror and progress to gotest.tools
This commit is contained in:
commit
b2655f15c4
|
@ -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: '###'")
|
||||
}
|
||||
|
|
|
@ -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")
|
||||
}
|
||||
|
|
|
@ -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)))
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue