kops/nodeup/pkg/model/docker_test.go

108 lines
2.4 KiB
Go

/*
Copyright 2016 The Kubernetes Authors.
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 model
import (
"k8s.io/kops/pkg/apis/kops"
"k8s.io/kops/upup/pkg/fi"
"path"
"testing"
// Register our APIs
_ "k8s.io/kops/pkg/apis/kops/install"
"k8s.io/kops/pkg/flagbuilder"
)
func TestDockerBuilder_Simple(t *testing.T) {
runDockerBuilderTest(t, "simple")
}
func TestDockerBuilder_1_12_1(t *testing.T) {
runDockerBuilderTest(t, "docker_1.12.1")
}
func TestDockerBuilder_LogFlags(t *testing.T) {
runDockerBuilderTest(t, "logflags")
}
func TestDockerBuilder_BuildFlags(t *testing.T) {
grid := []struct {
config kops.DockerConfig
expected string
}{
{
kops.DockerConfig{},
"",
},
{
kops.DockerConfig{
LogDriver: "json-file",
},
"--log-driver=json-file",
},
{
kops.DockerConfig{
LogDriver: "json-file",
LogOpt: []string{"max-size=10m"},
},
"--log-driver=json-file --log-opt=max-size=10m",
},
{
kops.DockerConfig{
LogDriver: "json-file",
LogOpt: []string{"max-size=10m", "max-file=5"},
},
"--log-driver=json-file --log-opt=max-file=5 --log-opt=max-size=10m",
},
}
for _, g := range grid {
actual, err := flagbuilder.BuildFlags(&g.config)
if err != nil {
t.Errorf("error building flags for %v: %v", g.config, err)
continue
}
if actual != g.expected {
t.Errorf("flags did not match. actual=%q expected=%q", actual, g.expected)
}
}
}
func runDockerBuilderTest(t *testing.T, key string) {
basedir := path.Join("tests/dockerbuilder/", key)
nodeUpModelContext, err := LoadModel(basedir)
if err != nil {
t.Fatalf("error parsing cluster yaml %q: %v", basedir, err)
return
}
context := &fi.ModelBuilderContext{
Tasks: make(map[string]fi.Task),
}
builder := DockerBuilder{NodeupModelContext: nodeUpModelContext}
err = builder.Build(context)
if err != nil {
t.Fatalf("error from DockerBuilder Build: %v", err)
return
}
ValidateTasks(t, basedir, context)
}