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

Added Test Cases for Pod #25678

Merged
merged 1 commit into from
May 29, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
84 changes: 83 additions & 1 deletion pkg/api/pod/util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,89 @@ func TestFindPort(t *testing.T) {
port: intstr.FromString("q"),
expected: 33,
pass: true,
}}
}, {
name: "valid str, two ctr with same port",
containers: []api.Container{{}, {Ports: []api.ContainerPort{{
Name: "",
ContainerPort: 11,
Protocol: "UDP",
}, {
Name: "p",
ContainerPort: 22,
Protocol: "TCP",
}, {
Name: "q",
ContainerPort: 22,
Protocol: "TCP",
}}}},
port: intstr.FromString("q"),
expected: 22,
pass: true,
}, {
name: "valid str, invalid protocol",
containers: []api.Container{{}, {Ports: []api.ContainerPort{{
Name: "a",
ContainerPort: 11,
Protocol: "snmp",
},
}}},
port: intstr.FromString("a"),
expected: 0,
pass: false,
}, {
name: "valid hostPort",
containers: []api.Container{{}, {Ports: []api.ContainerPort{{
Name: "a",
ContainerPort: 11,
HostPort: 81,
Protocol: "TCP",
},
}}},
port: intstr.FromString("a"),
expected: 11,
pass: true,
},
{
name: "invalid hostPort",
containers: []api.Container{{}, {Ports: []api.ContainerPort{{
Name: "a",
ContainerPort: 11,
HostPort: -1,
Protocol: "TCP",
},
}}},
port: intstr.FromString("a"),
expected: 11,
pass: true,
//this should fail but passes.
},
{
name: "invalid ContainerPort",
containers: []api.Container{{}, {Ports: []api.ContainerPort{{
Name: "a",
ContainerPort: -1,
Protocol: "TCP",
},
}}},
port: intstr.FromString("a"),
expected: -1,
pass: true,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would you also add a comment that this should fail as well

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

//this should fail but passes
},
{
name: "HostIP Address",
containers: []api.Container{{}, {Ports: []api.ContainerPort{{
Name: "a",
ContainerPort: 11,
HostIP: "192.168.1.1",
Protocol: "TCP",
},
}}},
port: intstr.FromString("a"),
expected: 11,
pass: true,
},
}

for _, tc := range testCases {
port, err := FindPort(&api.Pod{Spec: api.PodSpec{Containers: tc.containers}},
Expand Down