From 7c00201222e29989214b7e8a221b057daba0a27d Mon Sep 17 00:00:00 2001 From: Victor Vieux Date: Wed, 17 Jul 2013 20:51:25 +0000 Subject: [PATCH] add Volumes and VolumesFrom to CompareConfig --- utils.go | 11 +++++++++-- utils_test.go | 51 ++++++++++++++++++++++++++++++++++++++++++--------- 2 files changed, 51 insertions(+), 11 deletions(-) diff --git a/utils.go b/utils.go index 33cfbe506f..4f3a846d75 100644 --- a/utils.go +++ b/utils.go @@ -18,14 +18,16 @@ func CompareConfig(a, b *Config) bool { a.MemorySwap != b.MemorySwap || a.CpuShares != b.CpuShares || a.OpenStdin != b.OpenStdin || - a.Tty != b.Tty { + a.Tty != b.Tty || + a.VolumesFrom != b.VolumesFrom { return false } if len(a.Cmd) != len(b.Cmd) || len(a.Dns) != len(b.Dns) || len(a.Env) != len(b.Env) || len(a.PortSpecs) != len(b.PortSpecs) || - len(a.Entrypoint) != len(b.Entrypoint) { + len(a.Entrypoint) != len(b.Entrypoint) || + len(a.Volumes) != len(b.Volumes) { return false } @@ -54,6 +56,11 @@ func CompareConfig(a, b *Config) bool { return false } } + for key := range a.Volumes { + if _, exists := b.Volumes[key]; !exists { + return false + } + } return true } diff --git a/utils_test.go b/utils_test.go index 31489446f8..95f3d4bfdd 100644 --- a/utils_test.go +++ b/utils_test.go @@ -130,20 +130,44 @@ func runContainer(r *Runtime, args []string, t *testing.T) (output string, err e } func TestCompareConfig(t *testing.T) { + volumes1 := make(map[string]struct{}) + volumes1["/test1"] = struct{}{} config1 := Config{ - Dns: []string{"1.1.1.1", "2.2.2.2"}, - PortSpecs: []string{"1111:1111", "2222:2222"}, - Env: []string{"VAR1=1", "VAR2=2"}, + Dns: []string{"1.1.1.1", "2.2.2.2"}, + PortSpecs: []string{"1111:1111", "2222:2222"}, + Env: []string{"VAR1=1", "VAR2=2"}, + VolumesFrom: "11111111", + Volumes: volumes1, } config2 := Config{ - Dns: []string{"0.0.0.0", "2.2.2.2"}, - PortSpecs: []string{"1111:1111", "2222:2222"}, - Env: []string{"VAR1=1", "VAR2=2"}, + Dns: []string{"0.0.0.0", "2.2.2.2"}, + PortSpecs: []string{"1111:1111", "2222:2222"}, + Env: []string{"VAR1=1", "VAR2=2"}, + VolumesFrom: "11111111", + Volumes: volumes1, } config3 := Config{ - Dns: []string{"1.1.1.1", "2.2.2.2"}, - PortSpecs: []string{"0000:0000", "2222:2222"}, - Env: []string{"VAR1=1", "VAR2=2"}, + Dns: []string{"1.1.1.1", "2.2.2.2"}, + PortSpecs: []string{"0000:0000", "2222:2222"}, + Env: []string{"VAR1=1", "VAR2=2"}, + VolumesFrom: "11111111", + Volumes: volumes1, + } + config4 := Config{ + Dns: []string{"1.1.1.1", "2.2.2.2"}, + PortSpecs: []string{"0000:0000", "2222:2222"}, + Env: []string{"VAR1=1", "VAR2=2"}, + VolumesFrom: "22222222", + Volumes: volumes1, + } + volumes2 := make(map[string]struct{}) + volumes2["/test2"] = struct{}{} + config5 := Config{ + Dns: []string{"1.1.1.1", "2.2.2.2"}, + PortSpecs: []string{"0000:0000", "2222:2222"}, + Env: []string{"VAR1=1", "VAR2=2"}, + VolumesFrom: "11111111", + Volumes: volumes2, } if CompareConfig(&config1, &config2) { t.Fatalf("CompareConfig should return false, Dns are different") @@ -151,6 +175,15 @@ func TestCompareConfig(t *testing.T) { if CompareConfig(&config1, &config3) { t.Fatalf("CompareConfig should return false, PortSpecs are different") } + if CompareConfig(&config1, &config4) { + t.Fatalf("CompareConfig should return false, VolumesFrom are different") + } + if CompareConfig(&config1, &config5) { + t.Fatalf("CompareConfig should return false, Volumes are different") + } + if !CompareConfig(&config1, &config1) { + t.Fatalf("CompareConfig should return true") + } } func TestMergeConfig(t *testing.T) {