From 40ff87637d9c82aa4ed3aaace71a16971d263c1b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=8Dtalo=20Vietro?= Date: Fri, 11 Oct 2019 14:09:21 +0200 Subject: [PATCH] Update test to use testify framework (#12583) * Update test to use testify framework * Add require.NotNil to avoid a nil err var * Add missing test var --- model/command_webhook_test.go | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/model/command_webhook_test.go b/model/command_webhook_test.go index 629bbdaa70..141350b78a 100644 --- a/model/command_webhook_test.go +++ b/model/command_webhook_test.go @@ -5,17 +5,17 @@ package model import ( "testing" + + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" ) func TestCommandWebhookPreSave(t *testing.T) { h := CommandWebhook{} h.PreSave() - if len(h.Id) != 26 { - t.Fatal("Id should be generated") - } - if h.CreateAt == 0 { - t.Fatal("CreateAt should be set") - } + + require.Len(t, h.Id, 26, "Id should be generated") + require.NotEqual(t, 0, h.CreateAt, "CreateAt should be set") } func TestCommandWebhookIsValid(t *testing.T) { @@ -44,11 +44,14 @@ func TestCommandWebhookIsValid(t *testing.T) { tmp := h test.Transform() err := h.IsValid() - if test.ExpectedError == "" && err != nil { - t.Fatal("hook should be valid") - } else if test.ExpectedError != "" && test.ExpectedError != err.Id { - t.Fatal("expected " + test.ExpectedError + " error") + + if test.ExpectedError == "" { + assert.Error(t, err, "hook should be valid") + } else { + require.NotNil(t, err) + assert.Equal(t, test.ExpectedError, err.Id, "expected "+test.ExpectedError+" error") } + h = tmp } }