From 8655c06c74924a248039f49b5c9c412fb7c8d541 Mon Sep 17 00:00:00 2001 From: "James O. D. Hunt" Date: Wed, 7 Jun 2017 08:41:00 +0100 Subject: [PATCH] config: Add new tests for default values. Add tests to ensure default and overriden values are correct for hypervisor, proxy, shim and agent. Signed-off-by: James O. D. Hunt --- config_test.go | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) diff --git a/config_test.go b/config_test.go index a9d4ffb7..85f869d3 100644 --- a/config_test.go +++ b/config_test.go @@ -26,6 +26,7 @@ import ( vc "github.com/containers/virtcontainers" "github.com/containers/virtcontainers/pkg/oci" + "github.com/stretchr/testify/assert" ) const proxyURL = "foo:///foo/clear-containers/proxy.sock" @@ -494,3 +495,54 @@ func TestCheckConfigParams(t *testing.T) { } } } + +func TestHypervisorDefaults(t *testing.T) { + h := hypervisor{} + + assert.Equal(t, h.path(), defaultHypervisorPath, "default hypervisor path wrong") + assert.Equal(t, h.kernel(), defaultKernelPath, "default hypervisor kernel wrong") + assert.Equal(t, h.image(), defaultImagePath, "default hypervisor image wrong") + + path := "/foo" + h.Path = path + assert.Equal(t, h.path(), path, "custom hypervisor path wrong") + + kernel := "wibble" + h.Kernel = kernel + assert.Equal(t, h.kernel(), kernel, "custom hypervisor kernel wrong") + + image := "foo" + h.Image = image + assert.Equal(t, h.image(), image, "custom hypervisor image wrong") +} + +func TestProxyDefaults(t *testing.T) { + p := proxy{} + + assert.Equal(t, p.url(), defaultProxyURL, "default proxy url wrong") + + url := "unix:///hello/world.sock" + p.URL = url + assert.Equal(t, p.url(), url, "custom proxy url wrong") + +} + +func TestShimDefaults(t *testing.T) { + s := shim{} + + assert.Equal(t, s.path(), defaultShimPath, "default shim path wrong") + + path := "/foo/bar" + s.Path = path + assert.Equal(t, s.path(), path, "custom shim path wrong") +} + +func TestAgentDefaults(t *testing.T) { + a := agent{} + + assert.Equal(t, a.pauseRootPath(), defaultPauseRootPath, "default agent pause root path wrong") + + path := "/foo/bar/baz" + a.PauseRootPath = path + assert.Equal(t, a.pauseRootPath(), path, "custom agent pause root path wrong") +}