MM-19670: Migrate tests to use testify (#12883) (#12898)

* MM-19670: Migrate tests to use testify (#12883)

* MM-19670: (#12883) Applied changes requested in PR #12898

* MM-19670: (#12883) assert.Equal parameters are 'expected' and then 'actual'.
This commit is contained in:
ptisserand
2019-10-25 04:55:58 +02:00
committed by Jesse Hallam
parent b9329d1984
commit 6ce97648f4
2 changed files with 12 additions and 23 deletions

View File

@@ -6,6 +6,8 @@ package utils
import (
"testing"
"time"
"github.com/stretchr/testify/assert"
)
var format = "2006-01-02 15:04:05.000000000"
@@ -15,18 +17,16 @@ func TestMillisFromTime(t *testing.T) {
actual := MillisFromTime(input)
expected := int64(1420115640000)
if actual != expected {
t.Fatalf("TestMillisFromTime failed, %v=%v", expected, actual)
}
assert.Equal(t, expected, actual)
}
func TestYesterday(t *testing.T) {
actual := Yesterday()
expected := time.Now().AddDate(0, 0, -1)
if actual.Year() != expected.Year() || actual.Day() != expected.Day() || actual.Month() != expected.Month() {
t.Fatalf("TestYesterday failed, %v=%v", expected, actual)
}
assert.Equal(t, expected.Year(), actual.Year())
assert.Equal(t, expected.Day(), actual.Day())
assert.Equal(t, expected.Month(), actual.Month())
}
func TestStartOfDay(t *testing.T) {
@@ -34,9 +34,7 @@ func TestStartOfDay(t *testing.T) {
actual := StartOfDay(input)
expected, _ := time.Parse(format, "2015-01-01 00:00:00.000000000")
if actual != expected {
t.Fatalf("TestStartOfDay failed, %v=%v", expected, actual)
}
assert.Equal(t, expected, actual)
}
func TestEndOfDay(t *testing.T) {
@@ -44,7 +42,5 @@ func TestEndOfDay(t *testing.T) {
actual := EndOfDay(input)
expected, _ := time.Parse(format, "2015-01-01 23:59:59.999999999")
if actual != expected {
t.Fatalf("TestEndOfDay failed, %v=%v", expected, actual)
}
assert.Equal(t, expected, actual)
}

View File

@@ -23,13 +23,8 @@ func TestStringArrayIntersection(t *testing.T) {
"def",
}
if len(StringArrayIntersection(a, b)) != 0 {
t.Fatal("should be 0")
}
if len(StringArrayIntersection(a, c)) != 1 {
t.Fatal("should be 1")
}
assert.Len(t, StringArrayIntersection(a, b), 0)
assert.Len(t, StringArrayIntersection(a, c), 1)
}
func TestRemoveDuplicatesFromStringArray(t *testing.T) {
@@ -43,9 +38,7 @@ func TestRemoveDuplicatesFromStringArray(t *testing.T) {
"a",
}
if len(RemoveDuplicatesFromStringArray(a)) != 3 {
t.Fatal("should be 3")
}
assert.Len(t, RemoveDuplicatesFromStringArray(a), 3)
}
func TestStringSliceDiff(t *testing.T) {
@@ -53,7 +46,7 @@ func TestStringSliceDiff(t *testing.T) {
b := []string{"two", "seven", "four", "six"}
expected := []string{"one", "three", "five"}
assert.Equal(t, StringSliceDiff(a, b), expected)
assert.Equal(t, expected, StringSliceDiff(a, b))
}
func TestGetIpAddress(t *testing.T) {