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

add a test case for HostnameOverride #72771

Merged
merged 1 commit into from Aug 14, 2019
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
20 changes: 17 additions & 3 deletions cmd/kube-proxy/app/server_test.go
Expand Up @@ -381,16 +381,24 @@ func TestProcessHostnameOverrideFlag(t *testing.T) {
name string
hostnameOverrideFlag string
expectedHostname string
expectError bool
}{
{
name: "Hostname from config file",
hostnameOverrideFlag: "",
expectedHostname: "foo",
expectError: false,
},
{
name: "Hostname from flag",
hostnameOverrideFlag: " bar ",
expectedHostname: "bar",
expectError: false,
},
{
name: "Hostname is space",
Copy link
Contributor

Choose a reason for hiding this comment

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

why is this tested needed/useful?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

because the testcase didn't cover that:
image

hostnameOverrideFlag: " ",
expectError: true,
},
}
for _, tc := range testCases {
Expand All @@ -403,9 +411,15 @@ func TestProcessHostnameOverrideFlag(t *testing.T) {
options.hostnameOverride = tc.hostnameOverrideFlag

err := options.processHostnameOverrideFlag()
assert.NoError(t, err, "unexpected error %v", err)
if tc.expectedHostname != options.config.HostnameOverride {
t.Fatalf("expected hostname: %s, but got: %s", tc.expectedHostname, options.config.HostnameOverride)
if tc.expectError {
if err == nil {
t.Fatalf("should error for this case %s", tc.name)
}
} else {
assert.NoError(t, err, "unexpected error %v", err)
if tc.expectedHostname != options.config.HostnameOverride {
t.Fatalf("expected hostname: %s, but got: %s", tc.expectedHostname, options.config.HostnameOverride)
}
}
})
}
Expand Down