mirror of
https://github.com/kata-containers/kata-containers.git
synced 2025-08-13 21:56:32 +00:00
proxy/shim: add unit tests
To test built-in proxy and shim types. Signed-off-by: Peng Tao <bergwolf@gmail.com>
This commit is contained in:
parent
f483d6f8da
commit
81bb561467
42
virtcontainers/podlist_test.go
Normal file
42
virtcontainers/podlist_test.go
Normal file
@ -0,0 +1,42 @@
|
||||
//
|
||||
// Copyright (c) 2018 HyperHQ Inc.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
//
|
||||
|
||||
package virtcontainers
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestPodListOperations(t *testing.T) {
|
||||
p := &Pod{id: "testpodListpod"}
|
||||
l := &podList{pods: make(map[string]*Pod)}
|
||||
err := l.addPod(p)
|
||||
assert.Nil(t, err, "addPod failed")
|
||||
|
||||
err = l.addPod(p)
|
||||
assert.NotNil(t, err, "add same pod should fail")
|
||||
|
||||
np, err := l.lookupPod(p.id)
|
||||
assert.Nil(t, err, "lookupPod failed")
|
||||
assert.Equal(t, np, p, "lookupPod returns different pod %v:%v", np, p)
|
||||
|
||||
_, err = l.lookupPod("some-non-existing-pod-name")
|
||||
assert.NotNil(t, err, "lookupPod for non-existing pod should fail")
|
||||
|
||||
l.removePod(p.id)
|
||||
}
|
@ -52,6 +52,10 @@ func TestSetNoProxyType(t *testing.T) {
|
||||
testSetProxyType(t, "noProxy", NoProxyType)
|
||||
}
|
||||
|
||||
func TestSetKataBuiltInProxyType(t *testing.T) {
|
||||
testSetProxyType(t, "kataBuiltInProxy", KataBuiltInProxyType)
|
||||
}
|
||||
|
||||
func TestSetUnknownProxyType(t *testing.T) {
|
||||
var proxyType ProxyType
|
||||
|
||||
@ -97,6 +101,11 @@ func TestStringFromNoopProxyType(t *testing.T) {
|
||||
testStringFromProxyType(t, proxyType, "noopProxy")
|
||||
}
|
||||
|
||||
func TestStringFromKataBuiltInProxyType(t *testing.T) {
|
||||
proxyType := KataBuiltInProxyType
|
||||
testStringFromProxyType(t, proxyType, "kataBuiltInProxy")
|
||||
}
|
||||
|
||||
func TestStringFromUnknownProxyType(t *testing.T) {
|
||||
var proxyType ProxyType
|
||||
testStringFromProxyType(t, proxyType, "")
|
||||
@ -137,6 +146,12 @@ func TestNewProxyFromNoopProxyType(t *testing.T) {
|
||||
testNewProxyFromProxyType(t, proxyType, expectedProxy)
|
||||
}
|
||||
|
||||
func TestNewProxyFromKataBuiltInProxyType(t *testing.T) {
|
||||
proxyType := KataBuiltInProxyType
|
||||
expectedProxy := &kataBuiltInProxy{}
|
||||
testNewProxyFromProxyType(t, proxyType, expectedProxy)
|
||||
}
|
||||
|
||||
func TestNewProxyFromUnknownProxyType(t *testing.T) {
|
||||
var proxyType ProxyType
|
||||
|
||||
|
@ -89,6 +89,11 @@ func TestStringFromNoopShimType(t *testing.T) {
|
||||
testStringFromShimType(t, shimType, "noopShim")
|
||||
}
|
||||
|
||||
func TestStringFromKataBuiltInShimType(t *testing.T) {
|
||||
shimType := KataBuiltInShimType
|
||||
testStringFromShimType(t, shimType, "kataBuiltInShim")
|
||||
}
|
||||
|
||||
func TestStringFromUnknownShimType(t *testing.T) {
|
||||
var shimType ShimType
|
||||
testStringFromShimType(t, shimType, "")
|
||||
@ -123,6 +128,12 @@ func TestNewShimFromNoopShimType(t *testing.T) {
|
||||
testNewShimFromShimType(t, shimType, expectedShim)
|
||||
}
|
||||
|
||||
func TestNewShimFromKataBuiltInShimType(t *testing.T) {
|
||||
shimType := KataBuiltInShimType
|
||||
expectedShim := &kataBuiltInShim{}
|
||||
testNewShimFromShimType(t, shimType, expectedShim)
|
||||
}
|
||||
|
||||
func TestNewShimFromUnknownShimType(t *testing.T) {
|
||||
var shimType ShimType
|
||||
|
||||
@ -170,6 +181,14 @@ func TestNewShimConfigFromNoopShimPodConfig(t *testing.T) {
|
||||
testNewShimConfigFromPodConfig(t, podConfig, nil)
|
||||
}
|
||||
|
||||
func TestNewShimConfigFromKataBuiltInShimPodConfig(t *testing.T) {
|
||||
podConfig := PodConfig{
|
||||
ShimType: KataBuiltInShimType,
|
||||
}
|
||||
|
||||
testNewShimConfigFromPodConfig(t, podConfig, nil)
|
||||
}
|
||||
|
||||
func TestNewShimConfigFromUnknownShimPodConfig(t *testing.T) {
|
||||
var shimType ShimType
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user