c3f86cd016
The tests are trying to read an write configuration files and check that the fields are being set or saved properly. A folder fixtures/ was created on server/ as well adding an example crio.conf file to it. Note: some extra paths about Vagrant and VSCode were added to gitignore. Signed-off-by: Álex González <agonzalezro@gmail.com>
89 lines
2.4 KiB
Go
89 lines
2.4 KiB
Go
package server
|
|
|
|
import (
|
|
"io/ioutil"
|
|
"os"
|
|
"testing"
|
|
|
|
"github.com/kubernetes-incubator/cri-o/libkpod"
|
|
)
|
|
|
|
const fixturePath = "fixtures/crio.conf"
|
|
|
|
func must(t *testing.T, err error) {
|
|
if err != nil {
|
|
t.Error(err)
|
|
}
|
|
}
|
|
|
|
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, libkpod.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)
|
|
}
|