|
@@ -140,15 +140,73 @@ func runContainer(r *Runtime, args []string, t *testing.T) (output string, err e
|
|
|
return
|
|
|
}
|
|
|
|
|
|
+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"},
|
|
|
+ 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"},
|
|
|
+ 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"},
|
|
|
+ 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")
|
|
|
+ }
|
|
|
+ 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) {
|
|
|
volumesImage := make(map[string]struct{})
|
|
|
volumesImage["/test1"] = struct{}{}
|
|
|
volumesImage["/test2"] = struct{}{}
|
|
|
configImage := &Config{
|
|
|
- Dns: []string{"1.1.1.1", "2.2.2.2"},
|
|
|
- PortSpecs: []string{"1111:1111", "2222:2222"},
|
|
|
- Env: []string{"VAR1=1", "VAR2=2"},
|
|
|
- Volumes: volumesImage,
|
|
|
+ Dns: []string{"1.1.1.1", "2.2.2.2"},
|
|
|
+ PortSpecs: []string{"1111:1111", "2222:2222"},
|
|
|
+ Env: []string{"VAR1=1", "VAR2=2"},
|
|
|
+ VolumesFrom: "1111",
|
|
|
+ Volumes: volumesImage,
|
|
|
}
|
|
|
|
|
|
volumesUser := make(map[string]struct{})
|
|
@@ -196,6 +254,10 @@ func TestMergeConfig(t *testing.T) {
|
|
|
t.Fatalf("Expected /test1 or /test2 or /test3, found %s", v)
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ if configUser.VolumesFrom != "1111" {
|
|
|
+ t.Fatalf("Expected VolumesFrom to be 1111, found %s", configUser.VolumesFrom)
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
func TestMergeConfigPublicPortNotHonored(t *testing.T) {
|