Skip to content

Commit

Permalink
Merge pull request #1976 from devily/master
Browse files Browse the repository at this point in the history
test: add unit-test for apis/opts/ports.go

fixes #1906
  • Loading branch information
Wei Fu authored Aug 1, 2018
2 parents fe7fbd6 + 6ab4bed commit 703b26a
Showing 1 changed file with 39 additions and 1 deletion.
40 changes: 39 additions & 1 deletion apis/opts/ports_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,45 @@ func TestParseExposedPorts(t *testing.T) {
want map[string]interface{}
wantErr bool
}{
// TODO: Add test cases.
//Correct test case
//Use '-' represent multiple addresses
//The default method is '/tcp'
{
name: "test1",
args: args{
portList: []string{"8080-8081/udp", "22"},
expose: []string{"8082", "22-24/tcp"},
},
want: map[string]interface{}{
"8080/udp": struct{}{},
"8081/udp": struct{}{},
"8082/tcp": struct{}{},
"22/tcp": struct{}{},
"23/tcp": struct{}{},
"24/tcp": struct{}{},
},
wantErr: false,
},
//Input format error
{
name: "test2",
args: args{
portList: []string{"0.0.0.0:8080", "0.0.0.0:22"},
expose: []string{"0.0.0.0:8080", "0.0.0.0:22"},
},
want: nil,
wantErr: true,
},
//Input contains illegal characters (Chinese characters)
{
name: "test3",
args: args{
portList: []string{"8080", "8081"},
expose: []string{"8082/udp", "8081"},
},
want: nil,
wantErr: true,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
Expand Down

0 comments on commit 703b26a

Please sign in to comment.