mirror of
https://github.com/kata-containers/kata-containers.git
synced 2025-06-30 17:22:33 +00:00
tests: Refactor CC proxy test for Kata
Reworked `TestCCProxyStart` to create a generic `testProxyStart()` that is now used for testing both CC and Kata proxies. Signed-off-by: James O. D. Hunt <james.o.hunt@intel.com>
This commit is contained in:
parent
23eb13f23a
commit
a38b251120
@ -6,84 +6,11 @@
|
|||||||
package virtcontainers
|
package virtcontainers
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
|
||||||
"io/ioutil"
|
|
||||||
"os"
|
|
||||||
"path/filepath"
|
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/stretchr/testify/assert"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestCCProxyStart(t *testing.T) {
|
func TestCCProxyStart(t *testing.T) {
|
||||||
assert := assert.New(t)
|
|
||||||
|
|
||||||
tmpdir, err := ioutil.TempDir("", "")
|
|
||||||
assert.NoError(err)
|
|
||||||
defer os.RemoveAll(tmpdir)
|
|
||||||
|
|
||||||
proxy := &ccProxy{}
|
proxy := &ccProxy{}
|
||||||
|
|
||||||
type testData struct {
|
testProxyStart(t, nil, proxy, CCProxyType)
|
||||||
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)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
17
virtcontainers/kata_proxy_test.go
Normal file
17
virtcontainers/kata_proxy_test.go
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
// Copyright (c) 2018 Intel Corporation
|
||||||
|
//
|
||||||
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
|
//
|
||||||
|
|
||||||
|
package virtcontainers
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestKataProxyStart(t *testing.T) {
|
||||||
|
agent := &kataAgent{}
|
||||||
|
proxy := &kataProxy{}
|
||||||
|
|
||||||
|
testProxyStart(t, agent, proxy, KataProxyType)
|
||||||
|
}
|
@ -7,9 +7,13 @@ package virtcontainers
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"io/ioutil"
|
||||||
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"reflect"
|
"reflect"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
)
|
)
|
||||||
|
|
||||||
func testSetProxyType(t *testing.T, value string, expected ProxyType) {
|
func testSetProxyType(t *testing.T, value string, expected ProxyType) {
|
||||||
@ -248,3 +252,89 @@ func TestDefaultProxyURLUnknown(t *testing.T) {
|
|||||||
t.Fatal()
|
t.Fatal()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func testProxyStart(t *testing.T, agent agent, proxy proxy, proxyType ProxyType) {
|
||||||
|
assert := assert.New(t)
|
||||||
|
|
||||||
|
assert.NotNil(proxy)
|
||||||
|
|
||||||
|
tmpdir, err := ioutil.TempDir("", "")
|
||||||
|
assert.NoError(err)
|
||||||
|
defer os.RemoveAll(tmpdir)
|
||||||
|
|
||||||
|
type testData struct {
|
||||||
|
sandbox *Sandbox
|
||||||
|
params proxyParams
|
||||||
|
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{}, proxyParams{}, "", true},
|
||||||
|
{
|
||||||
|
&Sandbox{
|
||||||
|
config: &SandboxConfig{
|
||||||
|
ProxyType: "invalid",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
proxyParams{},
|
||||||
|
"", true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
&Sandbox{
|
||||||
|
config: &SandboxConfig{
|
||||||
|
ProxyType: proxyType,
|
||||||
|
// invalid - no path
|
||||||
|
ProxyConfig: ProxyConfig{},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
proxyParams{},
|
||||||
|
"", true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
&Sandbox{
|
||||||
|
config: &SandboxConfig{
|
||||||
|
ProxyType: proxyType,
|
||||||
|
ProxyConfig: ProxyConfig{
|
||||||
|
Path: invalidPath,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
proxyParams{},
|
||||||
|
"", true,
|
||||||
|
},
|
||||||
|
|
||||||
|
{
|
||||||
|
&Sandbox{
|
||||||
|
id: testSandboxID,
|
||||||
|
agent: agent,
|
||||||
|
config: &SandboxConfig{
|
||||||
|
ProxyType: proxyType,
|
||||||
|
ProxyConfig: ProxyConfig{
|
||||||
|
Path: "echo",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
proxyParams{
|
||||||
|
agentURL: "agentURL",
|
||||||
|
},
|
||||||
|
expectedURI, false,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, d := range data {
|
||||||
|
pid, uri, err := proxy.start(d.sandbox, d.params)
|
||||||
|
if d.expectError {
|
||||||
|
assert.Error(err)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
assert.NoError(err)
|
||||||
|
assert.True(pid > 0)
|
||||||
|
assert.Equal(d.expectedURI, uri)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user