tests: Refactors PodSandbox creation

Most of the tests creating and using Pod Sandboxes in the same way. We can create
a common function that will do that for us, so we can have less duplicated code,
and make it easier to add new tests in the future.

Signed-off-by: Claudiu Belu <cbelu@cloudbasesolutions.com>
This commit is contained in:
Claudiu Belu
2021-03-30 18:16:20 +03:00
parent ada96ec192
commit a78bdf22df
17 changed files with 56 additions and 175 deletions

View File

@@ -28,19 +28,12 @@ import (
)
func TestImageFSInfo(t *testing.T) {
config := PodSandboxConfig("running-pod", "imagefs")
t.Logf("Create a sandbox to make sure there is an active snapshot")
PodSandboxConfigWithCleanup(t, "running-pod", "imagefs")
t.Logf("Pull an image to make sure image fs is not empty")
EnsureImageExists(t, GetImage(BusyBox))
t.Logf("Create a sandbox to make sure there is an active snapshot")
sb, err := runtimeService.RunPodSandbox(config, *runtimeHandler)
require.NoError(t, err)
defer func() {
assert.NoError(t, runtimeService.StopPodSandbox(sb))
assert.NoError(t, runtimeService.RemovePodSandbox(sb))
}()
// It takes time to populate imagefs stats. Use eventually
// to check for a period of time.
t.Logf("Check imagefs info")
@@ -66,6 +59,6 @@ func TestImageFSInfo(t *testing.T) {
}, time.Second, 30*time.Second))
t.Logf("Image filesystem mountpath should exist")
_, err = os.Stat(info.GetFsId().GetMountpoint())
_, err := os.Stat(info.GetFsId().GetMountpoint())
assert.NoError(t, err)
}