mirror of
https://github.com/kata-containers/kata-containers.git
synced 2025-07-17 17:02:42 +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 (
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestCCProxyStart(t *testing.T) {
|
||||
@ -14,3 +16,13 @@ func TestCCProxyStart(t *testing.T) {
|
||||
|
||||
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{
|
||||
HypervisorType: vc.MockHypervisor,
|
||||
AgentType: vc.NoopAgentType,
|
||||
ProxyType: vc.NoopProxyType,
|
||||
HypervisorConfig: vc.HypervisorConfig{
|
||||
KernelPath: testDir,
|
||||
ImagePath: testDir,
|
||||
@ -109,6 +107,14 @@ func TestVMConfigValid(t *testing.T) {
|
||||
f := factory{}
|
||||
|
||||
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)
|
||||
}
|
||||
|
||||
@ -168,6 +174,9 @@ func TestFactoryGetVM(t *testing.T) {
|
||||
ProxyType: vc.NoopProxyType,
|
||||
}
|
||||
|
||||
err := vmConfig.Valid()
|
||||
assert.Nil(err)
|
||||
|
||||
ctx := context.Background()
|
||||
|
||||
// direct factory
|
||||
|
@ -35,6 +35,9 @@ func TestTemplateFactory(t *testing.T) {
|
||||
ProxyType: vc.NoopProxyType,
|
||||
}
|
||||
|
||||
err := vmConfig.Valid()
|
||||
assert.Nil(err)
|
||||
|
||||
ctx := context.Background()
|
||||
|
||||
// New
|
||||
@ -44,7 +47,7 @@ func TestTemplateFactory(t *testing.T) {
|
||||
assert.Equal(f.Config(), vmConfig)
|
||||
|
||||
// GetBaseVM
|
||||
_, err := f.GetBaseVM(ctx, vmConfig)
|
||||
_, err = f.GetBaseVM(ctx, vmConfig)
|
||||
assert.Nil(err)
|
||||
|
||||
// Fetch
|
||||
@ -53,6 +56,8 @@ func TestTemplateFactory(t *testing.T) {
|
||||
config: vmConfig,
|
||||
}
|
||||
|
||||
assert.Equal(tt.Config(), vmConfig)
|
||||
|
||||
err = tt.checkTemplateVM()
|
||||
assert.Error(err)
|
||||
|
||||
@ -69,13 +74,19 @@ func TestTemplateFactory(t *testing.T) {
|
||||
err = tt.createTemplateVM(ctx)
|
||||
assert.Error(err)
|
||||
|
||||
templateProxyType = vc.NoopProxyType
|
||||
_, err = tt.GetBaseVM(ctx, vmConfig)
|
||||
assert.Nil(err)
|
||||
|
||||
_, err = f.GetBaseVM(ctx, vmConfig)
|
||||
assert.Nil(err)
|
||||
|
||||
templateProxyType = vc.NoopProxyType
|
||||
err = tt.createTemplateVM(ctx)
|
||||
assert.Nil(err)
|
||||
|
||||
_, err = tt.GetBaseVM(ctx, vmConfig)
|
||||
assert.Nil(err)
|
||||
|
||||
_, err = f.GetBaseVM(ctx, vmConfig)
|
||||
assert.Nil(err)
|
||||
|
||||
|
@ -7,33 +7,30 @@ package virtcontainers
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestNoProxyStart(t *testing.T) {
|
||||
p := &noProxy{}
|
||||
assert := assert.New(t)
|
||||
|
||||
agentURL := "agentURL"
|
||||
_, _, err := p.start(proxyParams{
|
||||
agentURL: agentURL,
|
||||
})
|
||||
assert.NotNil(err)
|
||||
|
||||
pid, vmURL, err := p.start(proxyParams{
|
||||
agentURL: agentURL,
|
||||
logger: testDefaultLogger,
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
assert.Nil(err)
|
||||
assert.Equal(vmURL, agentURL)
|
||||
assert.Equal(pid, 0)
|
||||
|
||||
if vmURL != agentURL {
|
||||
t.Fatalf("Got URL %q, expecting %q", vmURL, agentURL)
|
||||
}
|
||||
err = p.stop(0)
|
||||
assert.Nil(err)
|
||||
|
||||
if pid != 0 {
|
||||
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)
|
||||
}
|
||||
assert.False(p.consoleWatched())
|
||||
}
|
||||
|
@ -44,6 +44,8 @@ func TestNewVM(t *testing.T) {
|
||||
assert.Nil(err)
|
||||
err = vm.Start()
|
||||
assert.Nil(err)
|
||||
err = vm.Disconnect()
|
||||
assert.Nil(err)
|
||||
err = vm.Save()
|
||||
assert.Nil(err)
|
||||
err = vm.Stop()
|
||||
@ -87,3 +89,24 @@ func TestVMConfigValid(t *testing.T) {
|
||||
err = config.Valid()
|
||||
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