container_create: correctly set image and kube envs

Signed-off-by: Antonio Murdaca <runcom@redhat.com>
This commit is contained in:
Antonio Murdaca 2017-11-30 11:52:30 +01:00
parent b59f31a2d5
commit 902acca4af
No known key found for this signature in database
GPG key ID: B2BEAD150DE936B9
3 changed files with 80 additions and 24 deletions

View file

@ -4,6 +4,9 @@ import (
"io/ioutil"
"os"
"testing"
"github.com/opencontainers/image-spec/specs-go/v1"
pb "k8s.io/kubernetes/pkg/kubelet/apis/cri/v1alpha1/runtime"
)
const (
@ -108,3 +111,33 @@ func TestSysctlsFromPodAnnotations(t *testing.T) {
}
}
}
func TestMergeEnvs(t *testing.T) {
configImage := &v1.Image{
Config: v1.ImageConfig{
Env: []string{"VAR1=1", "VAR2=2"},
},
}
configKube := []*pb.KeyValue{
{
Key: "VAR2",
Value: "3",
},
{
Key: "VAR3",
Value: "3",
},
}
mergedEnvs := mergeEnvs(configImage, configKube)
if len(mergedEnvs) != 3 {
t.Fatalf("Expected 3 env var, VAR1=1, VAR2=3 and VAR3=3, found %d", len(mergedEnvs))
}
for _, env := range mergedEnvs {
if env != "VAR1=1" && env != "VAR2=3" && env != "VAR3=3" {
t.Fatalf("Expected VAR1=1 or VAR2=3 or VAR3=3, found %s", env)
}
}
}