tests: replace cmd.Diff() with require functions

This commit is contained in:
Alexander Todorov 2020-04-09 05:03:16 -04:00 committed by Tom Gundersen
parent fb7373aa62
commit cd1e6d3aaf

View file

@ -6,7 +6,6 @@ import (
"net/http" "net/http"
"testing" "testing"
"github.com/google/go-cmp/cmp"
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
) )
@ -33,9 +32,7 @@ func TestRequest(t *testing.T) {
func TestAPIErrorMsg(t *testing.T) { func TestAPIErrorMsg(t *testing.T) {
err := APIErrorMsg{ID: "ERROR_ID", Msg: "Meaningful error message"} err := APIErrorMsg{ID: "ERROR_ID", Msg: "Meaningful error message"}
if diff := cmp.Diff(err.String(), "ERROR_ID: Meaningful error message"); diff != "" { require.Equal(t, "ERROR_ID: Meaningful error message", err.String())
t.Fatalf("APIErrorMsg: %s", diff)
}
} }
func TestAPIResponse(t *testing.T) { func TestAPIResponse(t *testing.T) {
@ -47,12 +44,10 @@ func TestAPIResponse(t *testing.T) {
{ID: "ONE_ERROR", Msg: "First message"}, {ID: "ONE_ERROR", Msg: "First message"},
{ID: "TWO_ERROR", Msg: "Second message"}}, {ID: "TWO_ERROR", Msg: "Second message"}},
} }
if diff := cmp.Diff(resp.String(), "ONE_ERROR: First message"); diff != "" { require.Equal(t, "ONE_ERROR: First message", resp.String())
t.Fatalf("APIResponse.Error: %s", diff) require.ElementsMatch(t, []string{
} "ONE_ERROR: First message",
if diff := cmp.Diff(resp.AllErrors(), []string{"ONE_ERROR: First message", "TWO_ERROR: Second message"}); diff != "" { "TWO_ERROR: Second message"}, resp.AllErrors())
t.Fatalf("APIErrorMsg: %s", diff)
}
} }
func TestGetRaw(t *testing.T) { func TestGetRaw(t *testing.T) {