From fcee080a2dd61c5772ffd8d1d8ff4da1452113f7 Mon Sep 17 00:00:00 2001 From: Jose Carlos Venegas Munoz Date: Thu, 28 Feb 2019 17:21:52 -0600 Subject: [PATCH] unit-test: Fix local test Simplify empty string proxy type handling and cast invalid proxy type to ProxyType. Fixes: #1312 Signed-off-by: Jose Carlos Venegas Munoz --- virtcontainers/api_test.go | 10 ++++++++++ virtcontainers/proxy.go | 4 +++- virtcontainers/vm.go | 7 +------ virtcontainers/vm_test.go | 2 +- 4 files changed, 15 insertions(+), 8 deletions(-) diff --git a/virtcontainers/api_test.go b/virtcontainers/api_test.go index 1d77f812a4..742a1b39b2 100644 --- a/virtcontainers/api_test.go +++ b/virtcontainers/api_test.go @@ -86,6 +86,8 @@ func newTestSandboxConfigNoop() SandboxConfig { Containers: []ContainerConfig{container}, Annotations: sandboxAnnotations, + + ProxyType: NoopProxyType, } return sandboxConfig @@ -122,6 +124,8 @@ func newTestSandboxConfigHyperstartAgent() SandboxConfig { Containers: []ContainerConfig{container}, Annotations: sandboxAnnotations, + + ProxyType: NoopProxyType, } return sandboxConfig @@ -163,6 +167,8 @@ func newTestSandboxConfigHyperstartAgentDefaultNetwork() SandboxConfig { Containers: []ContainerConfig{container}, Annotations: sandboxAnnotations, + + ProxyType: NoopProxyType, } return sandboxConfig @@ -184,6 +190,8 @@ func newTestSandboxConfigKataAgent() SandboxConfig { AgentType: KataContainersAgent, Annotations: sandboxAnnotations, + + ProxyType: NoopProxyType, } return sandboxConfig @@ -2014,6 +2022,8 @@ func createNewSandboxConfig(hType HypervisorType, aType AgentType, aConfig inter AgentConfig: aConfig, NetworkConfig: netConfig, + + ProxyType: NoopProxyType, } } diff --git a/virtcontainers/proxy.go b/virtcontainers/proxy.go index 2d79847af3..051c8c1ff8 100644 --- a/virtcontainers/proxy.go +++ b/virtcontainers/proxy.go @@ -109,6 +109,8 @@ func (pType *ProxyType) String() string { // newProxy returns a proxy from a proxy type. func newProxy(pType ProxyType) (proxy, error) { switch pType { + case "": + return &kataBuiltInProxy{}, nil case NoopProxyType: return &noopProxy{}, nil case NoProxyType: @@ -120,7 +122,7 @@ func newProxy(pType ProxyType) (proxy, error) { case KataBuiltInProxyType: return &kataBuiltInProxy{}, nil default: - return &noopProxy{}, nil + return &noopProxy{}, fmt.Errorf("Invalid proxy type: %s", pType) } } diff --git a/virtcontainers/vm.go b/virtcontainers/vm.go index e04f521727..ea0e6c3042 100644 --- a/virtcontainers/vm.go +++ b/virtcontainers/vm.go @@ -62,12 +62,7 @@ func setupProxy(h hypervisor, agent agent, config VMConfig, id string) (int, str return -1, "", nil, err } - // default to kata builtin proxy - proxyType := config.ProxyType - if len(proxyType.String()) == 0 { - proxyType = KataBuiltInProxyType - } - proxy, err := newProxy(proxyType) + proxy, err := newProxy(config.ProxyType) if err != nil { return -1, "", nil, err } diff --git a/virtcontainers/vm_test.go b/virtcontainers/vm_test.go index 40a9729d6b..5fda0f98ab 100644 --- a/virtcontainers/vm_test.go +++ b/virtcontainers/vm_test.go @@ -102,7 +102,7 @@ func TestSetupProxy(t *testing.T) { agent := &noopAgent{} // wrong proxy type - config.ProxyType = "invalidProxyType" + config.ProxyType = ProxyType("invalidProxyType") _, _, _, err := setupProxy(hypervisor, agent, config, "foobar") assert.NotNil(err)