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:
@@ -181,6 +181,18 @@ func PodSandboxConfig(name, ns string, opts ...PodSandboxOpts) *runtime.PodSandb
|
||||
return config
|
||||
}
|
||||
|
||||
func PodSandboxConfigWithCleanup(t *testing.T, name, ns string, opts ...PodSandboxOpts) (string, *runtime.PodSandboxConfig) {
|
||||
sbConfig := PodSandboxConfig(name, ns, opts...)
|
||||
sb, err := runtimeService.RunPodSandbox(sbConfig, *runtimeHandler)
|
||||
require.NoError(t, err)
|
||||
t.Cleanup(func() {
|
||||
assert.NoError(t, runtimeService.StopPodSandbox(sb))
|
||||
assert.NoError(t, runtimeService.RemovePodSandbox(sb))
|
||||
})
|
||||
|
||||
return sb, sbConfig
|
||||
}
|
||||
|
||||
// ContainerOpts to set any specific attribute like labels,
|
||||
// annotations, metadata etc
|
||||
type ContainerOpts func(*runtime.ContainerConfig)
|
||||
|
Reference in New Issue
Block a user