mirror of
https://github.com/kata-containers/kata-containers.git
synced 2025-07-18 17:33:02 +00:00
ut: add more UTs
Let's make codecov happier;) Signed-off-by: Peng Tao <bergwolf@gmail.com>
This commit is contained in:
parent
07c1f18e51
commit
d75841ef23
@ -7,6 +7,8 @@ package virtcontainers
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestCCProxyStart(t *testing.T) {
|
func TestCCProxyStart(t *testing.T) {
|
||||||
@ -14,3 +16,13 @@ func TestCCProxyStart(t *testing.T) {
|
|||||||
|
|
||||||
testProxyStart(t, nil, proxy)
|
testProxyStart(t, nil, proxy)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestCCProxy(t *testing.T) {
|
||||||
|
proxy := &ccProxy{}
|
||||||
|
assert := assert.New(t)
|
||||||
|
|
||||||
|
err := proxy.stop(0)
|
||||||
|
assert.Nil(err)
|
||||||
|
|
||||||
|
assert.False(proxy.consoleWatched())
|
||||||
|
}
|
||||||
|
@ -98,8 +98,6 @@ func TestVMConfigValid(t *testing.T) {
|
|||||||
|
|
||||||
config := vc.VMConfig{
|
config := vc.VMConfig{
|
||||||
HypervisorType: vc.MockHypervisor,
|
HypervisorType: vc.MockHypervisor,
|
||||||
AgentType: vc.NoopAgentType,
|
|
||||||
ProxyType: vc.NoopProxyType,
|
|
||||||
HypervisorConfig: vc.HypervisorConfig{
|
HypervisorConfig: vc.HypervisorConfig{
|
||||||
KernelPath: testDir,
|
KernelPath: testDir,
|
||||||
ImagePath: testDir,
|
ImagePath: testDir,
|
||||||
@ -109,6 +107,14 @@ func TestVMConfigValid(t *testing.T) {
|
|||||||
f := factory{}
|
f := factory{}
|
||||||
|
|
||||||
err := f.validateNewVMConfig(config)
|
err := f.validateNewVMConfig(config)
|
||||||
|
assert.NotNil(err)
|
||||||
|
|
||||||
|
config.AgentType = vc.NoopAgentType
|
||||||
|
err = f.validateNewVMConfig(config)
|
||||||
|
assert.NotNil(err)
|
||||||
|
|
||||||
|
config.ProxyType = vc.NoopProxyType
|
||||||
|
err = f.validateNewVMConfig(config)
|
||||||
assert.Nil(err)
|
assert.Nil(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -168,6 +174,9 @@ func TestFactoryGetVM(t *testing.T) {
|
|||||||
ProxyType: vc.NoopProxyType,
|
ProxyType: vc.NoopProxyType,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
err := vmConfig.Valid()
|
||||||
|
assert.Nil(err)
|
||||||
|
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
|
|
||||||
// direct factory
|
// direct factory
|
||||||
|
@ -35,6 +35,9 @@ func TestTemplateFactory(t *testing.T) {
|
|||||||
ProxyType: vc.NoopProxyType,
|
ProxyType: vc.NoopProxyType,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
err := vmConfig.Valid()
|
||||||
|
assert.Nil(err)
|
||||||
|
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
|
|
||||||
// New
|
// New
|
||||||
@ -44,7 +47,7 @@ func TestTemplateFactory(t *testing.T) {
|
|||||||
assert.Equal(f.Config(), vmConfig)
|
assert.Equal(f.Config(), vmConfig)
|
||||||
|
|
||||||
// GetBaseVM
|
// GetBaseVM
|
||||||
_, err := f.GetBaseVM(ctx, vmConfig)
|
_, err = f.GetBaseVM(ctx, vmConfig)
|
||||||
assert.Nil(err)
|
assert.Nil(err)
|
||||||
|
|
||||||
// Fetch
|
// Fetch
|
||||||
@ -53,6 +56,8 @@ func TestTemplateFactory(t *testing.T) {
|
|||||||
config: vmConfig,
|
config: vmConfig,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
assert.Equal(tt.Config(), vmConfig)
|
||||||
|
|
||||||
err = tt.checkTemplateVM()
|
err = tt.checkTemplateVM()
|
||||||
assert.Error(err)
|
assert.Error(err)
|
||||||
|
|
||||||
@ -69,13 +74,19 @@ func TestTemplateFactory(t *testing.T) {
|
|||||||
err = tt.createTemplateVM(ctx)
|
err = tt.createTemplateVM(ctx)
|
||||||
assert.Error(err)
|
assert.Error(err)
|
||||||
|
|
||||||
|
templateProxyType = vc.NoopProxyType
|
||||||
|
_, err = tt.GetBaseVM(ctx, vmConfig)
|
||||||
|
assert.Nil(err)
|
||||||
|
|
||||||
_, err = f.GetBaseVM(ctx, vmConfig)
|
_, err = f.GetBaseVM(ctx, vmConfig)
|
||||||
assert.Nil(err)
|
assert.Nil(err)
|
||||||
|
|
||||||
templateProxyType = vc.NoopProxyType
|
|
||||||
err = tt.createTemplateVM(ctx)
|
err = tt.createTemplateVM(ctx)
|
||||||
assert.Nil(err)
|
assert.Nil(err)
|
||||||
|
|
||||||
|
_, err = tt.GetBaseVM(ctx, vmConfig)
|
||||||
|
assert.Nil(err)
|
||||||
|
|
||||||
_, err = f.GetBaseVM(ctx, vmConfig)
|
_, err = f.GetBaseVM(ctx, vmConfig)
|
||||||
assert.Nil(err)
|
assert.Nil(err)
|
||||||
|
|
||||||
|
@ -7,33 +7,30 @@ package virtcontainers
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestNoProxyStart(t *testing.T) {
|
func TestNoProxyStart(t *testing.T) {
|
||||||
p := &noProxy{}
|
p := &noProxy{}
|
||||||
|
assert := assert.New(t)
|
||||||
|
|
||||||
agentURL := "agentURL"
|
agentURL := "agentURL"
|
||||||
|
_, _, err := p.start(proxyParams{
|
||||||
|
agentURL: agentURL,
|
||||||
|
})
|
||||||
|
assert.NotNil(err)
|
||||||
|
|
||||||
pid, vmURL, err := p.start(proxyParams{
|
pid, vmURL, err := p.start(proxyParams{
|
||||||
agentURL: agentURL,
|
agentURL: agentURL,
|
||||||
logger: testDefaultLogger,
|
logger: testDefaultLogger,
|
||||||
})
|
})
|
||||||
if err != nil {
|
assert.Nil(err)
|
||||||
t.Fatal(err)
|
assert.Equal(vmURL, agentURL)
|
||||||
}
|
assert.Equal(pid, 0)
|
||||||
|
|
||||||
if vmURL != agentURL {
|
err = p.stop(0)
|
||||||
t.Fatalf("Got URL %q, expecting %q", vmURL, agentURL)
|
assert.Nil(err)
|
||||||
}
|
|
||||||
|
|
||||||
if pid != 0 {
|
assert.False(p.consoleWatched())
|
||||||
t.Fatal("Failure since returned PID should be 0")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestNoProxyStop(t *testing.T) {
|
|
||||||
p := &noProxy{}
|
|
||||||
|
|
||||||
if err := p.stop(0); err != nil {
|
|
||||||
t.Fatal(err)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -44,6 +44,8 @@ func TestNewVM(t *testing.T) {
|
|||||||
assert.Nil(err)
|
assert.Nil(err)
|
||||||
err = vm.Start()
|
err = vm.Start()
|
||||||
assert.Nil(err)
|
assert.Nil(err)
|
||||||
|
err = vm.Disconnect()
|
||||||
|
assert.Nil(err)
|
||||||
err = vm.Save()
|
err = vm.Save()
|
||||||
assert.Nil(err)
|
assert.Nil(err)
|
||||||
err = vm.Stop()
|
err = vm.Stop()
|
||||||
@ -87,3 +89,24 @@ func TestVMConfigValid(t *testing.T) {
|
|||||||
err = config.Valid()
|
err = config.Valid()
|
||||||
assert.Nil(err)
|
assert.Nil(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestSetupProxy(t *testing.T) {
|
||||||
|
assert := assert.New(t)
|
||||||
|
|
||||||
|
config := VMConfig{
|
||||||
|
HypervisorType: MockHypervisor,
|
||||||
|
AgentType: NoopAgentType,
|
||||||
|
}
|
||||||
|
|
||||||
|
hypervisor := &mockHypervisor{}
|
||||||
|
agent := &noopAgent{}
|
||||||
|
|
||||||
|
// wrong proxy type
|
||||||
|
config.ProxyType = "invalidProxyType"
|
||||||
|
_, _, _, err := setupProxy(hypervisor, agent, config, "foobar")
|
||||||
|
assert.NotNil(err)
|
||||||
|
|
||||||
|
config.ProxyType = NoopProxyType
|
||||||
|
_, _, _, err = setupProxy(hypervisor, agent, config, "foobar")
|
||||||
|
assert.Nil(err)
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user