Files
kata-containers/virtcontainers/cc_proxy_test.go
Sebastien Boeuf 644489b6e7 virtcontainers: Fix gofmt issues for Go 1.10
Now that our CI has moved to Go 1.10, we need to update one file
that is not formatted as the new gofmt (1.10) expects it to be
formatted.

Fixes #249

Signed-off-by: Sebastien Boeuf <sebastien.boeuf@intel.com>
2018-04-26 11:38:15 -05:00

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)
}
}