forked from moby/moby
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor test and add coverage to runconfig
Signed-off-by: Vincent Demeester <[email protected]>
- Loading branch information
1 parent
bb2cd98
commit d4aec5f
Showing
10 changed files
with
1,217 additions
and
241 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
package runconfig | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/docker/docker/pkg/nat" | ||
) | ||
|
||
func TestCompare(t *testing.T) { | ||
ports1 := make(nat.PortSet) | ||
ports1[nat.Port("1111/tcp")] = struct{}{} | ||
ports1[nat.Port("2222/tcp")] = struct{}{} | ||
ports2 := make(nat.PortSet) | ||
ports2[nat.Port("3333/tcp")] = struct{}{} | ||
ports2[nat.Port("4444/tcp")] = struct{}{} | ||
ports3 := make(nat.PortSet) | ||
ports3[nat.Port("1111/tcp")] = struct{}{} | ||
ports3[nat.Port("2222/tcp")] = struct{}{} | ||
ports3[nat.Port("5555/tcp")] = struct{}{} | ||
volumes1 := make(map[string]struct{}) | ||
volumes1["/test1"] = struct{}{} | ||
volumes2 := make(map[string]struct{}) | ||
volumes2["/test2"] = struct{}{} | ||
volumes3 := make(map[string]struct{}) | ||
volumes3["/test1"] = struct{}{} | ||
volumes3["/test3"] = struct{}{} | ||
envs1 := []string{"ENV1=value1", "ENV2=value2"} | ||
envs2 := []string{"ENV1=value1", "ENV3=value3"} | ||
entrypoint1 := &Entrypoint{parts: []string{"/bin/sh", "-c"}} | ||
entrypoint2 := &Entrypoint{parts: []string{"/bin/sh", "-d"}} | ||
entrypoint3 := &Entrypoint{parts: []string{"/bin/sh", "-c", "echo"}} | ||
cmd1 := &Command{parts: []string{"/bin/sh", "-c"}} | ||
cmd2 := &Command{parts: []string{"/bin/sh", "-d"}} | ||
cmd3 := &Command{parts: []string{"/bin/sh", "-c", "echo"}} | ||
labels1 := map[string]string{"LABEL1": "value1", "LABEL2": "value2"} | ||
labels2 := map[string]string{"LABEL1": "value1", "LABEL2": "value3"} | ||
labels3 := map[string]string{"LABEL1": "value1", "LABEL2": "value2", "LABEL3": "value3"} | ||
|
||
sameConfigs := map[*Config]*Config{ | ||
// Empty config | ||
&Config{}: {}, | ||
// Does not compare hostname, domainname & image | ||
&Config{ | ||
Hostname: "host1", | ||
Domainname: "domain1", | ||
Image: "image1", | ||
User: "user", | ||
}: { | ||
Hostname: "host2", | ||
Domainname: "domain2", | ||
Image: "image2", | ||
User: "user", | ||
}, | ||
// only OpenStdin | ||
&Config{OpenStdin: false}: {OpenStdin: false}, | ||
// only env | ||
&Config{Env: envs1}: {Env: envs1}, | ||
// only cmd | ||
&Config{Cmd: cmd1}: {Cmd: cmd1}, | ||
// only labels | ||
&Config{Labels: labels1}: {Labels: labels1}, | ||
// only exposedPorts | ||
&Config{ExposedPorts: ports1}: {ExposedPorts: ports1}, | ||
// only entrypoints | ||
&Config{Entrypoint: entrypoint1}: {Entrypoint: entrypoint1}, | ||
// only volumes | ||
&Config{Volumes: volumes1}: {Volumes: volumes1}, | ||
} | ||
differentConfigs := map[*Config]*Config{ | ||
nil: nil, | ||
&Config{ | ||
Hostname: "host1", | ||
Domainname: "domain1", | ||
Image: "image1", | ||
User: "user1", | ||
}: { | ||
Hostname: "host1", | ||
Domainname: "domain1", | ||
Image: "image1", | ||
User: "user2", | ||
}, | ||
// only OpenStdin | ||
&Config{OpenStdin: false}: {OpenStdin: true}, | ||
&Config{OpenStdin: true}: {OpenStdin: false}, | ||
// only env | ||
&Config{Env: envs1}: {Env: envs2}, | ||
// only cmd | ||
&Config{Cmd: cmd1}: {Cmd: cmd2}, | ||
// not the same number of parts | ||
&Config{Cmd: cmd1}: {Cmd: cmd3}, | ||
// only labels | ||
&Config{Labels: labels1}: {Labels: labels2}, | ||
// not the same number of labels | ||
&Config{Labels: labels1}: {Labels: labels3}, | ||
// only exposedPorts | ||
&Config{ExposedPorts: ports1}: {ExposedPorts: ports2}, | ||
// not the same number of ports | ||
&Config{ExposedPorts: ports1}: {ExposedPorts: ports3}, | ||
// only entrypoints | ||
&Config{Entrypoint: entrypoint1}: {Entrypoint: entrypoint2}, | ||
// not the same number of parts | ||
&Config{Entrypoint: entrypoint1}: {Entrypoint: entrypoint3}, | ||
// only volumes | ||
&Config{Volumes: volumes1}: {Volumes: volumes2}, | ||
// not the same number of labels | ||
&Config{Volumes: volumes1}: {Volumes: volumes3}, | ||
} | ||
for config1, config2 := range sameConfigs { | ||
if !Compare(config1, config2) { | ||
t.Fatalf("Compare should be true for [%v] and [%v]", config1, config2) | ||
} | ||
} | ||
for config1, config2 := range differentConfigs { | ||
if Compare(config1, config2) { | ||
t.Fatalf("Compare should be false for [%v] and [%v]", config1, config2) | ||
} | ||
} | ||
} |
Oops, something went wrong.