gitee.com/leisunstar/runtime@v0.0.0-20200521203717-5cef3e7b53f9/virtcontainers/mock_hypervisor_test.go (about) 1 // Copyright (c) 2016 Intel Corporation 2 // 3 // SPDX-License-Identifier: Apache-2.0 4 // 5 6 package virtcontainers 7 8 import ( 9 "context" 10 "fmt" 11 "testing" 12 13 "github.com/stretchr/testify/assert" 14 ) 15 16 func TestMockHypervisorCreateSandbox(t *testing.T) { 17 var m *mockHypervisor 18 assert := assert.New(t) 19 20 sandbox := &Sandbox{ 21 config: &SandboxConfig{ 22 ID: "mock_sandbox", 23 HypervisorConfig: HypervisorConfig{ 24 KernelPath: "", 25 ImagePath: "", 26 HypervisorPath: "", 27 }, 28 }, 29 } 30 31 ctx := context.Background() 32 33 // wrong config 34 err := m.createSandbox(ctx, sandbox.config.ID, NetworkNamespace{}, &sandbox.config.HypervisorConfig, false) 35 assert.Error(err) 36 37 sandbox.config.HypervisorConfig = HypervisorConfig{ 38 KernelPath: fmt.Sprintf("%s/%s", testDir, testKernel), 39 ImagePath: fmt.Sprintf("%s/%s", testDir, testImage), 40 HypervisorPath: fmt.Sprintf("%s/%s", testDir, testHypervisor), 41 } 42 43 err = m.createSandbox(ctx, sandbox.config.ID, NetworkNamespace{}, &sandbox.config.HypervisorConfig, false) 44 assert.NoError(err) 45 } 46 47 func TestMockHypervisorStartSandbox(t *testing.T) { 48 var m *mockHypervisor 49 50 assert.NoError(t, m.startSandbox(vmStartTimeout)) 51 } 52 53 func TestMockHypervisorStopSandbox(t *testing.T) { 54 var m *mockHypervisor 55 56 assert.NoError(t, m.stopSandbox()) 57 } 58 59 func TestMockHypervisorAddDevice(t *testing.T) { 60 var m *mockHypervisor 61 62 assert.NoError(t, m.addDevice(nil, imgDev)) 63 } 64 65 func TestMockHypervisorGetSandboxConsole(t *testing.T) { 66 var m *mockHypervisor 67 68 expected := "" 69 result, err := m.getSandboxConsole("testSandboxID") 70 assert.NoError(t, err) 71 assert.Equal(t, result, expected) 72 } 73 74 func TestMockHypervisorSaveSandbox(t *testing.T) { 75 var m *mockHypervisor 76 77 assert.NoError(t, m.saveSandbox()) 78 } 79 80 func TestMockHypervisorDisconnect(t *testing.T) { 81 var m *mockHypervisor 82 83 m.disconnect() 84 } 85 86 func TestMockHypervisorCheck(t *testing.T) { 87 var m *mockHypervisor 88 89 assert.NoError(t, m.check()) 90 } 91 92 func TestMockGenerateSocket(t *testing.T) { 93 var m *mockHypervisor 94 95 i, err := m.generateSocket("a", true) 96 assert.NoError(t, err) 97 assert.NotNil(t, i) 98 }