mirror of
https://github.com/kata-containers/kata-containers.git
synced 2025-07-02 02:02:24 +00:00
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 <jose.carlos.venegas.munoz@intel.com>
This commit is contained in:
parent
dbfd96583a
commit
fcee080a2d
@ -86,6 +86,8 @@ func newTestSandboxConfigNoop() SandboxConfig {
|
|||||||
Containers: []ContainerConfig{container},
|
Containers: []ContainerConfig{container},
|
||||||
|
|
||||||
Annotations: sandboxAnnotations,
|
Annotations: sandboxAnnotations,
|
||||||
|
|
||||||
|
ProxyType: NoopProxyType,
|
||||||
}
|
}
|
||||||
|
|
||||||
return sandboxConfig
|
return sandboxConfig
|
||||||
@ -122,6 +124,8 @@ func newTestSandboxConfigHyperstartAgent() SandboxConfig {
|
|||||||
|
|
||||||
Containers: []ContainerConfig{container},
|
Containers: []ContainerConfig{container},
|
||||||
Annotations: sandboxAnnotations,
|
Annotations: sandboxAnnotations,
|
||||||
|
|
||||||
|
ProxyType: NoopProxyType,
|
||||||
}
|
}
|
||||||
|
|
||||||
return sandboxConfig
|
return sandboxConfig
|
||||||
@ -163,6 +167,8 @@ func newTestSandboxConfigHyperstartAgentDefaultNetwork() SandboxConfig {
|
|||||||
|
|
||||||
Containers: []ContainerConfig{container},
|
Containers: []ContainerConfig{container},
|
||||||
Annotations: sandboxAnnotations,
|
Annotations: sandboxAnnotations,
|
||||||
|
|
||||||
|
ProxyType: NoopProxyType,
|
||||||
}
|
}
|
||||||
|
|
||||||
return sandboxConfig
|
return sandboxConfig
|
||||||
@ -184,6 +190,8 @@ func newTestSandboxConfigKataAgent() SandboxConfig {
|
|||||||
AgentType: KataContainersAgent,
|
AgentType: KataContainersAgent,
|
||||||
|
|
||||||
Annotations: sandboxAnnotations,
|
Annotations: sandboxAnnotations,
|
||||||
|
|
||||||
|
ProxyType: NoopProxyType,
|
||||||
}
|
}
|
||||||
|
|
||||||
return sandboxConfig
|
return sandboxConfig
|
||||||
@ -2014,6 +2022,8 @@ func createNewSandboxConfig(hType HypervisorType, aType AgentType, aConfig inter
|
|||||||
AgentConfig: aConfig,
|
AgentConfig: aConfig,
|
||||||
|
|
||||||
NetworkConfig: netConfig,
|
NetworkConfig: netConfig,
|
||||||
|
|
||||||
|
ProxyType: NoopProxyType,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -109,6 +109,8 @@ func (pType *ProxyType) String() string {
|
|||||||
// newProxy returns a proxy from a proxy type.
|
// newProxy returns a proxy from a proxy type.
|
||||||
func newProxy(pType ProxyType) (proxy, error) {
|
func newProxy(pType ProxyType) (proxy, error) {
|
||||||
switch pType {
|
switch pType {
|
||||||
|
case "":
|
||||||
|
return &kataBuiltInProxy{}, nil
|
||||||
case NoopProxyType:
|
case NoopProxyType:
|
||||||
return &noopProxy{}, nil
|
return &noopProxy{}, nil
|
||||||
case NoProxyType:
|
case NoProxyType:
|
||||||
@ -120,7 +122,7 @@ func newProxy(pType ProxyType) (proxy, error) {
|
|||||||
case KataBuiltInProxyType:
|
case KataBuiltInProxyType:
|
||||||
return &kataBuiltInProxy{}, nil
|
return &kataBuiltInProxy{}, nil
|
||||||
default:
|
default:
|
||||||
return &noopProxy{}, nil
|
return &noopProxy{}, fmt.Errorf("Invalid proxy type: %s", pType)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -62,12 +62,7 @@ func setupProxy(h hypervisor, agent agent, config VMConfig, id string) (int, str
|
|||||||
return -1, "", nil, err
|
return -1, "", nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
// default to kata builtin proxy
|
proxy, err := newProxy(config.ProxyType)
|
||||||
proxyType := config.ProxyType
|
|
||||||
if len(proxyType.String()) == 0 {
|
|
||||||
proxyType = KataBuiltInProxyType
|
|
||||||
}
|
|
||||||
proxy, err := newProxy(proxyType)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return -1, "", nil, err
|
return -1, "", nil, err
|
||||||
}
|
}
|
||||||
|
@ -102,7 +102,7 @@ func TestSetupProxy(t *testing.T) {
|
|||||||
agent := &noopAgent{}
|
agent := &noopAgent{}
|
||||||
|
|
||||||
// wrong proxy type
|
// wrong proxy type
|
||||||
config.ProxyType = "invalidProxyType"
|
config.ProxyType = ProxyType("invalidProxyType")
|
||||||
_, _, _, err := setupProxy(hypervisor, agent, config, "foobar")
|
_, _, _, err := setupProxy(hypervisor, agent, config, "foobar")
|
||||||
assert.NotNil(err)
|
assert.NotNil(err)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user