Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BJ266-4: Add unit-test for apis/opts/ports.go, fix #1906 #1976

Merged
merged 1 commit into from
Aug 1, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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