docker/runconfig/config_test.go

63 строки
1.3 KiB
Go

package runconfig
import (
"bytes"
"fmt"
"io/ioutil"
"runtime"
"testing"
"github.com/docker/docker/pkg/stringutils"
)
type f struct {
file string
entrypoint *stringutils.StrSlice
}
func TestDecodeContainerConfig(t *testing.T) {
var (
fixtures []f
image string
)
if runtime.GOOS != "windows" {
image = "ubuntu"
fixtures = []f{
{"fixtures/unix/container_config_1_14.json", stringutils.NewStrSlice()},
{"fixtures/unix/container_config_1_17.json", stringutils.NewStrSlice("bash")},
{"fixtures/unix/container_config_1_19.json", stringutils.NewStrSlice("bash")},
}
} else {
image = "windows"
fixtures = []f{
{"fixtures/windows/container_config_1_19.json", stringutils.NewStrSlice("cmd")},
}
}
for _, f := range fixtures {
b, err := ioutil.ReadFile(f.file)
if err != nil {
t.Fatal(err)
}
c, h, err := DecodeContainerConfig(bytes.NewReader(b))
if err != nil {
t.Fatal(fmt.Errorf("Error parsing %s: %v", f, err))
}
if c.Image != image {
t.Fatalf("Expected %s image, found %s\n", image, c.Image)
}
if c.Entrypoint.Len() != f.entrypoint.Len() {
t.Fatalf("Expected %v, found %v\n", f.entrypoint, c.Entrypoint)
}
if h != nil && h.Memory != 1000 {
t.Fatalf("Expected memory to be 1000, found %d\n", h.Memory)
}
}
}