From 125d026aae9e5d72697c7350b5edbb0dc3d8ad3c Mon Sep 17 00:00:00 2001 From: Euan Kemp Date: Thu, 20 Oct 2016 10:46:57 -0700 Subject: [PATCH] oomparser: Fix tests They had reflect.Equal instead of !reflect.Equal. They also depended on the current year. Which changed. --- utils/oomparser/oomparser_test.go | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/utils/oomparser/oomparser_test.go b/utils/oomparser/oomparser_test.go index 8b0e2733..29521c24 100644 --- a/utils/oomparser/oomparser_test.go +++ b/utils/oomparser/oomparser_test.go @@ -18,10 +18,11 @@ import ( "bufio" "fmt" "os" - "reflect" "strconv" "testing" "time" + + "github.com/stretchr/testify/assert" ) const startLine = "Jan 21 22:01:49 localhost kernel: [62278.816267] ruby invoked oom-killer: gfp_mask=0x201da, order=0, oom_score_adj=0" @@ -32,7 +33,7 @@ const systemLogFile = "systemOomExampleLog.txt" func createExpectedContainerOomInstance(t *testing.T) *OomInstance { const longForm = "Jan _2 15:04:05 2006" - deathTime, err := time.ParseInLocation(longForm, "Jan 5 15:19:27 2015", time.Local) + deathTime, err := time.ParseInLocation(longForm, fmt.Sprintf("Jan 5 15:19:27 %d", time.Now().Year()), time.Local) if err != nil { t.Fatalf("could not parse expected time when creating expected container oom instance. Had error %v", err) return nil @@ -42,13 +43,13 @@ func createExpectedContainerOomInstance(t *testing.T) *OomInstance { ProcessName: "memorymonster", TimeOfDeath: deathTime, ContainerName: "/mem2", - VictimContainerName: "/mem3", + VictimContainerName: "/mem2", } } func createExpectedSystemOomInstance(t *testing.T) *OomInstance { const longForm = "Jan _2 15:04:05 2006" - deathTime, err := time.ParseInLocation(longForm, "Jan 28 19:58:45 2015", time.Local) + deathTime, err := time.ParseInLocation(longForm, fmt.Sprintf("Jan 28 19:58:45 %d", time.Now().Year()), time.Local) if err != nil { t.Fatalf("could not parse expected time when creating expected system oom instance. Had error %v", err) return nil @@ -58,7 +59,7 @@ func createExpectedSystemOomInstance(t *testing.T) *OomInstance { ProcessName: "badsysprogram", TimeOfDeath: deathTime, ContainerName: "/", - VictimContainerName: "/", + VictimContainerName: "", } } @@ -148,10 +149,7 @@ func helpTestStreamOoms(oomCheckInstance *OomInstance, sysFile string, t *testin select { case oomInstance := <-outStream: - if reflect.DeepEqual(*oomCheckInstance, *oomInstance) { - t.Errorf("wrong instance returned. Expected %v and got %v", - oomCheckInstance, oomInstance) - } + assert.Equal(t, oomCheckInstance, oomInstance) case <-timeout: t.Error( "timeout happened before oomInstance was found in test file")