Refactor test for findPort in service pkg
This commit is contained in:
@@ -79,45 +79,59 @@ func TestFindPort(t *testing.T) {
|
||||
},
|
||||
},
|
||||
}
|
||||
port, err := findPort(&manifest, util.IntOrString{Kind: util.IntstrString, StrVal: "foo"})
|
||||
if err != nil {
|
||||
t.Errorf("unexpected error: %v", err)
|
||||
tests := []struct {
|
||||
portName util.IntOrString
|
||||
|
||||
wport int
|
||||
werr bool
|
||||
}{
|
||||
{
|
||||
util.IntOrString{Kind: util.IntstrString, StrVal: "foo"},
|
||||
8080,
|
||||
false,
|
||||
},
|
||||
{
|
||||
util.IntOrString{Kind: util.IntstrString, StrVal: "bar"},
|
||||
8000,
|
||||
false,
|
||||
},
|
||||
{
|
||||
util.IntOrString{Kind: util.IntstrInt, IntVal: 8000},
|
||||
8000,
|
||||
false,
|
||||
},
|
||||
{
|
||||
util.IntOrString{Kind: util.IntstrInt, IntVal: 7000},
|
||||
7000,
|
||||
false,
|
||||
},
|
||||
{
|
||||
util.IntOrString{Kind: util.IntstrString, StrVal: "baz"},
|
||||
0,
|
||||
true,
|
||||
},
|
||||
{
|
||||
util.IntOrString{Kind: util.IntstrString, StrVal: ""},
|
||||
8080,
|
||||
false,
|
||||
},
|
||||
{
|
||||
util.IntOrString{},
|
||||
8080,
|
||||
false,
|
||||
},
|
||||
}
|
||||
if port != 8080 {
|
||||
t.Errorf("Expected 8080, Got %d", port)
|
||||
}
|
||||
port, err = findPort(&manifest, util.IntOrString{Kind: util.IntstrString, StrVal: "bar"})
|
||||
if err != nil {
|
||||
t.Errorf("unexpected error: %v", err)
|
||||
}
|
||||
if port != 8000 {
|
||||
t.Errorf("Expected 8000, Got %d", port)
|
||||
}
|
||||
port, err = findPort(&manifest, util.IntOrString{Kind: util.IntstrInt, IntVal: 8000})
|
||||
if port != 8000 {
|
||||
t.Errorf("Expected 8000, Got %d", port)
|
||||
}
|
||||
port, err = findPort(&manifest, util.IntOrString{Kind: util.IntstrInt, IntVal: 7000})
|
||||
if port != 7000 {
|
||||
t.Errorf("Expected 7000, Got %d", port)
|
||||
}
|
||||
port, err = findPort(&manifest, util.IntOrString{Kind: util.IntstrString, StrVal: "baz"})
|
||||
if err == nil {
|
||||
t.Error("unexpected non-error")
|
||||
}
|
||||
port, err = findPort(&manifest, util.IntOrString{Kind: util.IntstrString, StrVal: ""})
|
||||
if err != nil {
|
||||
t.Errorf("unexpected error: %v", err)
|
||||
}
|
||||
if port != 8080 {
|
||||
t.Errorf("Expected 8080, Got %d", port)
|
||||
}
|
||||
port, err = findPort(&manifest, util.IntOrString{})
|
||||
if err != nil {
|
||||
t.Errorf("unexpected error: %v", err)
|
||||
}
|
||||
if port != 8080 {
|
||||
t.Errorf("Expected 8080, Got %d", port)
|
||||
for _, test := range tests {
|
||||
port, err := findPort(&manifest, test.portName)
|
||||
if port != test.wport {
|
||||
t.Errorf("Expected port %d, Got %d", test.wport, port)
|
||||
}
|
||||
if err == nil && test.werr {
|
||||
t.Errorf("unexpected non-error")
|
||||
}
|
||||
if err != nil && test.werr == false {
|
||||
t.Errorf("unexpected error: %v", err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user