mirror of
https://github.com/aljazceru/kata-containers.git
synced 2025-12-22 08:44:25 +01:00
Currently we sometimes pass it as a pointer and other times not. As a result, the view of sandbox across virtcontainers may not be the same and it costs extra memory copy each time we pass it by value. Fix it by ensuring sandbox is always passed by pointers. Fixes: #262 Signed-off-by: Peng Tao <bergwolf@gmail.com>
90 lines
1.5 KiB
Go
90 lines
1.5 KiB
Go
// Copyright (c) 2017 Intel Corporation
|
|
//
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
//
|
|
|
|
package virtcontainers
|
|
|
|
import (
|
|
"fmt"
|
|
"io/ioutil"
|
|
"os"
|
|
"path/filepath"
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
func TestCCProxyStart(t *testing.T) {
|
|
assert := assert.New(t)
|
|
|
|
tmpdir, err := ioutil.TempDir("", "")
|
|
assert.NoError(err)
|
|
defer os.RemoveAll(tmpdir)
|
|
|
|
proxy := &ccProxy{}
|
|
|
|
type testData struct {
|
|
sandbox *Sandbox
|
|
expectedURI string
|
|
expectError bool
|
|
}
|
|
|
|
invalidPath := filepath.Join(tmpdir, "enoent")
|
|
expectedSocketPath := filepath.Join(runStoragePath, testSandboxID, "proxy.sock")
|
|
expectedURI := fmt.Sprintf("unix://%s", expectedSocketPath)
|
|
|
|
data := []testData{
|
|
{&Sandbox{}, "", true},
|
|
{
|
|
&Sandbox{
|
|
config: &SandboxConfig{
|
|
ProxyType: "invalid",
|
|
},
|
|
}, "", true,
|
|
},
|
|
{
|
|
&Sandbox{
|
|
config: &SandboxConfig{
|
|
ProxyType: CCProxyType,
|
|
// invalid - no path
|
|
ProxyConfig: ProxyConfig{},
|
|
},
|
|
}, "", true,
|
|
},
|
|
{
|
|
&Sandbox{
|
|
config: &SandboxConfig{
|
|
ProxyType: CCProxyType,
|
|
ProxyConfig: ProxyConfig{
|
|
Path: invalidPath,
|
|
},
|
|
},
|
|
}, "", true,
|
|
},
|
|
{
|
|
&Sandbox{
|
|
id: testSandboxID,
|
|
config: &SandboxConfig{
|
|
ProxyType: CCProxyType,
|
|
ProxyConfig: ProxyConfig{
|
|
Path: "echo",
|
|
},
|
|
},
|
|
}, expectedURI, false,
|
|
},
|
|
}
|
|
|
|
for _, d := range data {
|
|
pid, uri, err := proxy.start(d.sandbox, proxyParams{})
|
|
if d.expectError {
|
|
assert.Error(err)
|
|
continue
|
|
}
|
|
|
|
assert.NoError(err)
|
|
assert.True(pid > 0)
|
|
assert.Equal(d.expectedURI, uri)
|
|
}
|
|
}
|