Skip to content

Commit

Permalink
unit-test: Fix local test
Browse files Browse the repository at this point in the history
Simplify empty string proxy type handling and cast invalid proxy type to
ProxyType.

Fixes: kata-containers#1312

Signed-off-by: Jose Carlos Venegas Munoz <[email protected]>
  • Loading branch information
jcvenegas committed Mar 5, 2019
1 parent dbfd965 commit fcee080
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 8 deletions.
10 changes: 10 additions & 0 deletions virtcontainers/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,8 @@ func newTestSandboxConfigNoop() SandboxConfig {
Containers: []ContainerConfig{container},

Annotations: sandboxAnnotations,

ProxyType: NoopProxyType,
}

return sandboxConfig
Expand Down Expand Up @@ -122,6 +124,8 @@ func newTestSandboxConfigHyperstartAgent() SandboxConfig {

Containers: []ContainerConfig{container},
Annotations: sandboxAnnotations,

ProxyType: NoopProxyType,
}

return sandboxConfig
Expand Down Expand Up @@ -163,6 +167,8 @@ func newTestSandboxConfigHyperstartAgentDefaultNetwork() SandboxConfig {

Containers: []ContainerConfig{container},
Annotations: sandboxAnnotations,

ProxyType: NoopProxyType,
}

return sandboxConfig
Expand All @@ -184,6 +190,8 @@ func newTestSandboxConfigKataAgent() SandboxConfig {
AgentType: KataContainersAgent,

Annotations: sandboxAnnotations,

ProxyType: NoopProxyType,
}

return sandboxConfig
Expand Down Expand Up @@ -2014,6 +2022,8 @@ func createNewSandboxConfig(hType HypervisorType, aType AgentType, aConfig inter
AgentConfig: aConfig,

NetworkConfig: netConfig,

ProxyType: NoopProxyType,
}
}

Expand Down
4 changes: 3 additions & 1 deletion virtcontainers/proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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)
}
}

Expand Down
7 changes: 1 addition & 6 deletions virtcontainers/vm.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
2 changes: 1 addition & 1 deletion virtcontainers/vm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down

0 comments on commit fcee080

Please sign in to comment.