From 24fe6e950c5c384a052b320b3473b1fa70c088f9 Mon Sep 17 00:00:00 2001 From: Miloslav Trmač Date: Wed, 25 Jul 2018 04:12:29 +0200 Subject: Use testify/require in a few places to avoid panics in tests MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Miloslav Trmač Closes: #1115 Approved by: rhatdan --- libpod/state_test.go | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/libpod/state_test.go b/libpod/state_test.go index 30638024c..827847049 100644 --- a/libpod/state_test.go +++ b/libpod/state_test.go @@ -10,6 +10,7 @@ import ( "github.com/containers/storage" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" ) // Returns state, tmp directory containing all state files, locks directory @@ -275,7 +276,7 @@ func TestAddCtrDepInPodFails(t *testing.T) { ctrs, err := state.AllContainers() assert.NoError(t, err) - assert.Equal(t, 1, len(ctrs)) + require.Len(t, ctrs, 1) testContainersEqual(t, testCtr1, ctrs[0]) }) @@ -688,7 +689,7 @@ func TestSaveAndUpdateContainer(t *testing.T) { assert.NoError(t, err) retrievedCtr, err := state.Container(testCtr.ID()) - assert.NoError(t, err) + require.NoError(t, err) retrievedCtr.state.State = ContainerStateStopped retrievedCtr.state.ExitCode = 127 @@ -880,7 +881,7 @@ func TestGetAllContainersWithOneContainer(t *testing.T) { ctrs, err := state.AllContainers() assert.NoError(t, err) - assert.Equal(t, 1, len(ctrs)) + require.Len(t, ctrs, 1) testContainersEqual(t, testCtr, ctrs[0]) }) @@ -2335,7 +2336,7 @@ func TestPodContainersOneContainer(t *testing.T) { ctrs, err := state.PodContainers(testPod) assert.NoError(t, err) - assert.Equal(t, 1, len(ctrs)) + require.Len(t, ctrs, 1) testContainersEqual(t, testCtr, ctrs[0]) }) @@ -2637,11 +2638,11 @@ func TestAddContainerToPodSucceeds(t *testing.T) { ctrs, err := state.PodContainers(testPod) assert.NoError(t, err) - assert.Equal(t, 1, len(ctrs)) + require.Len(t, ctrs, 1) allCtrs, err := state.AllContainers() assert.NoError(t, err) - assert.Equal(t, 1, len(allCtrs)) + require.Len(t, allCtrs, 1) testContainersEqual(t, testCtr, ctrs[0]) testContainersEqual(t, ctrs[0], allCtrs[0]) @@ -2703,7 +2704,7 @@ func TestAddContainerToPodWithAddContainer(t *testing.T) { ctrs, err := state.PodContainers(testPod) assert.NoError(t, err) - assert.Equal(t, 1, len(ctrs)) + require.Len(t, ctrs, 1) allCtrs, err := state.AllContainers() assert.NoError(t, err) -- cgit v1.2.3-54-g00ecf