If PodSandboxStatusRequest.Verbose is true now we are returning the cri-o version in a JSON object for debug purposes. In the future extra information (to be defined) should be added to the response In order to avoid problems when we execute the tests in parallel the fixtures for new test sandbox and container are creating their own random IDs and returning them in case you need to refer to them. Finally, "make testunit" is being run as root to solve a problem with a `chown` that couldn't be performed otherwise. This commit closes #1144 Signed-off-by: Álex González <agonzalezro@gmail.com>
83 lines
2.3 KiB
Go
83 lines
2.3 KiB
Go
package server
|
|
|
|
import (
|
|
"io/ioutil"
|
|
"os"
|
|
"testing"
|
|
|
|
"github.com/kubernetes-incubator/cri-o/lib"
|
|
)
|
|
|
|
const fixturePath = "fixtures/crio.conf"
|
|
|
|
func assertAllFieldsEquality(t *testing.T, c Config) {
|
|
testCases := []struct {
|
|
fieldValue, expected interface{}
|
|
}{
|
|
{c.RootConfig.Root, "/var/lib/containers/storage"},
|
|
{c.RootConfig.RunRoot, "/var/run/containers/storage"},
|
|
{c.RootConfig.Storage, "overlay"},
|
|
{c.RootConfig.StorageOptions[0], "overlay.override_kernel_check=1"},
|
|
|
|
{c.APIConfig.Listen, "/var/run/crio.sock"},
|
|
{c.APIConfig.StreamPort, "10010"},
|
|
{c.APIConfig.StreamAddress, "localhost"},
|
|
|
|
{c.RuntimeConfig.Runtime, "/usr/local/bin/runc"},
|
|
{c.RuntimeConfig.RuntimeUntrustedWorkload, "untrusted"},
|
|
{c.RuntimeConfig.DefaultWorkloadTrust, "trusted"},
|
|
{c.RuntimeConfig.Conmon, "/usr/local/libexec/crio/conmon"},
|
|
{c.RuntimeConfig.ConmonEnv[0], "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"},
|
|
{c.RuntimeConfig.SELinux, true},
|
|
{c.RuntimeConfig.SeccompProfile, "/etc/crio/seccomp.json"},
|
|
{c.RuntimeConfig.ApparmorProfile, "crio-default"},
|
|
{c.RuntimeConfig.CgroupManager, "cgroupfs"},
|
|
{c.RuntimeConfig.PidsLimit, int64(1024)},
|
|
|
|
{c.ImageConfig.DefaultTransport, "docker://"},
|
|
{c.ImageConfig.PauseImage, "kubernetes/pause"},
|
|
{c.ImageConfig.PauseCommand, "/pause"},
|
|
{c.ImageConfig.SignaturePolicyPath, "/tmp"},
|
|
{c.ImageConfig.ImageVolumes, lib.ImageVolumesType("mkdir")},
|
|
{c.ImageConfig.InsecureRegistries[0], "insecure-registry:1234"},
|
|
{c.ImageConfig.Registries[0], "registry:4321"},
|
|
|
|
{c.NetworkConfig.NetworkDir, "/etc/cni/net.d/"},
|
|
{c.NetworkConfig.PluginDir, "/opt/cni/bin/"},
|
|
}
|
|
for _, tc := range testCases {
|
|
if tc.fieldValue != tc.expected {
|
|
t.Errorf(`Expecting: "%s", got: "%s"`, tc.expected, tc.fieldValue)
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestUpdateFromFile(t *testing.T) {
|
|
c := Config{}
|
|
|
|
must(t, c.UpdateFromFile(fixturePath))
|
|
|
|
assertAllFieldsEquality(t, c)
|
|
}
|
|
|
|
func TestToFile(t *testing.T) {
|
|
configFromFixture := Config{}
|
|
|
|
must(t, configFromFixture.UpdateFromFile(fixturePath))
|
|
|
|
f, err := ioutil.TempFile("", "crio.conf")
|
|
if err != nil {
|
|
t.Error(err)
|
|
}
|
|
defer os.Remove(f.Name())
|
|
|
|
must(t, configFromFixture.ToFile(f.Name()))
|
|
|
|
writtenConfig := Config{}
|
|
err = writtenConfig.UpdateFromFile(f.Name())
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
assertAllFieldsEquality(t, writtenConfig)
|
|
}
|