Changes to kubectl taint to respect selector flag

This commit is contained in:
ravisantoshgudimetla
2017-04-20 17:27:09 -04:00
parent 6bf7914a71
commit 081ba02fa5
2 changed files with 77 additions and 11 deletions

View File

@@ -86,6 +86,7 @@ func TestTaint(t *testing.T) {
args []string
expectFatal bool
expectTaint bool
selector bool
}{
// success cases
{
@@ -237,7 +238,6 @@ func TestTaint(t *testing.T) {
for _, test := range tests {
oldNode, expectNewNode := generateNodeAndTaintedNode(test.oldTaints, test.newTaints)
new_node := &v1.Node{}
tainted := false
f, tf, codec, ns := cmdtesting.NewAPIFactory()
@@ -248,6 +248,8 @@ func TestTaint(t *testing.T) {
Client: fake.CreateHTTPClient(func(req *http.Request) (*http.Response, error) {
m := &MyReq{req}
switch {
case m.isFor("GET", "/nodes"):
return &http.Response{StatusCode: 200, Header: defaultHeader(), Body: objBody(codec, oldNode)}, nil
case m.isFor("GET", "/nodes/node-name"):
return &http.Response{StatusCode: 200, Header: defaultHeader(), Body: objBody(codec, oldNode)}, nil
case m.isFor("PATCH", "/nodes/node-name"):
@@ -332,3 +334,50 @@ func TestTaint(t *testing.T) {
}
}
}
func TestValidateFlags(t *testing.T) {
tests := []struct {
taintOpts TaintOptions
description string
expectFatal bool
}{
{
taintOpts: TaintOptions{selector: "myLabel=X", all: false},
description: "With Selector and without All flag",
expectFatal: false,
},
{
taintOpts: TaintOptions{selector: "", all: true},
description: "Without selector and All flag",
expectFatal: false,
},
{
taintOpts: TaintOptions{selector: "myLabel=X", all: true},
description: "With Selector and with All flag",
expectFatal: true,
},
{
taintOpts: TaintOptions{selector: "", all: false, resources: []string{"node"}},
description: "Without Selector and All flags and if node name is not provided",
expectFatal: true,
},
{
taintOpts: TaintOptions{selector: "", all: false, resources: []string{"node", "node-name"}},
description: "Without Selector and ALL flags and if node name is provided",
expectFatal: false,
},
}
for _, test := range tests {
sawFatal := false
err := test.taintOpts.validateFlags()
if err != nil {
sawFatal = true
}
if test.expectFatal {
if !sawFatal {
t.Fatalf("%s expected not to fail", test.description)
}
}
}
}