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

Issue1911 #2024

Closed
wants to merge 11 commits into from
Closed
Show file tree
Hide file tree
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
136 changes: 134 additions & 2 deletions apis/opts/portbindings_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,81 @@ func TestParsePortBinding(t *testing.T) {
want types.PortMap
wantErr bool
}{
// TODO: Add test cases.

{
name: "normal test",
args: args{ports: []string{"192.168.0.1:8080:1010"}},
want: types.PortMap(map[string][]types.PortBinding{
"1010/tcp": []types.PortBinding{
types.PortBinding{HostIP: "192.168.0.1", HostPort: "8080"},
},
}),
wantErr: false,
},

{
name: "test small ip",
args: args{ports: []string{"0.0.0.0.:8080:1010"}},
want: types.PortMap(map[string][]types.PortBinding{
"1010/tcp": []types.PortBinding{
types.PortBinding{HostIP: "0.0.0.0", HostPort: "8080"},
},
}),
wantErr: false,
},

{
name: "test big ip",
args: args{ports: []string{"256.256.256.256:8080:1010"}},
want: types.PortMap(map[string][]types.PortBinding{
"1010/tcp": []types.PortBinding{
types.PortBinding{HostIP: "256.256.256.256", HostPort: "8080"},
},
}),
wantErr: false,
},
{
name: "test host small port",
args: args{ports: []string{"192.168.0.1:0:1010"}},
want: types.PortMap(map[string][]types.PortBinding{
"1010/tcp": []types.PortBinding{
types.PortBinding{HostIP: "192.168.0.1", HostPort: "0"},
},
}),
wantErr: false,
},
{
name: "test host big port",
args: args{ports: []string{"192.168.0.1:65536:1010"}},
want: types.PortMap(map[string][]types.PortBinding{
"1010/tcp": []types.PortBinding{
types.PortBinding{HostIP: "192.168.0.1", HostPort: "65535"},
},
}),
wantErr: false,
},

{
name: "test container small port",
args: args{ports: []string{"192.168.0.1:8080:0"}},
want: types.PortMap(map[string][]types.PortBinding{
"0/tcp": []types.PortBinding{
types.PortBinding{HostIP: "192.168.0.1", HostPort: "8080"},
},
}),
wantErr: false,
},

{
name: "test container big port",
args: args{ports: []string{"192.168.0.1:8080:65536"}},
want: types.PortMap(map[string][]types.PortBinding{
"65536/tcp": []types.PortBinding{
types.PortBinding{HostIP: "192.168.0.1", HostPort: "8080"},
},
}),
wantErr: false,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
Expand All @@ -42,7 +116,65 @@ func TestVerifyPortBinding(t *testing.T) {
args args
wantErr bool
}{
// TODO: Add test cases.
{
name: "test normal port",
args: args{
types.PortMap(map[string][]types.PortBinding{
"1010/tcp": []types.PortBinding{
types.PortBinding{HostIP: "192.168.0.1", HostPort: "8080"},
},
}),
},
wantErr: false,
},

{
name: "test small ip",
args: args{
types.PortMap(map[string][]types.PortBinding{
"1010/tcp": []types.PortBinding{
types.PortBinding{HostIP: "0.0.0.0", HostPort: "8080"},
},
}),
},
wantErr: false,
},

{
name: "test big ip",
args: args{
types.PortMap(map[string][]types.PortBinding{
"1010/tcp": []types.PortBinding{
types.PortBinding{HostIP: "65536.65536.65536.65536", HostPort: "8080"},
},
}),
},
wantErr: false,
},

{
name: "test small port",
args: args{
types.PortMap(map[string][]types.PortBinding{
"1010/tcp": []types.PortBinding{
types.PortBinding{HostIP: "192.168.0.1", HostPort: "0"},
},
}),
},
wantErr: false,
},

{
name: "test big port",
args: args{
types.PortMap(map[string][]types.PortBinding{
"1010/tcp": []types.PortBinding{
types.PortBinding{HostIP: "192.168.0.1", HostPort: "65536"},
},
}),
},
wantErr: false,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
Expand Down
5 changes: 2 additions & 3 deletions cri/v1alpha1/cri_utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -570,6 +570,7 @@ func Test_makeContainerName(t *testing.T) {
}

func Test_modifyContainerNamespaceOptions(t *testing.T) {

type args struct {
nsOpts *runtime.NamespaceOption
podSandboxID string
Expand All @@ -578,9 +579,7 @@ func Test_modifyContainerNamespaceOptions(t *testing.T) {
tests := []struct {
name string
args args
}{
// TODO: Add test cases.
}
}{}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
modifyContainerNamespaceOptions(tt.args.nsOpts, tt.args.podSandboxID, tt.args.hostConfig)
Expand Down