make taint.ToString() consistent with the reverse parsing logic

This commit is contained in:
SataQiu 2019-07-16 21:06:01 +08:00
parent e12f96adc6
commit 23b7ae6041
4 changed files with 40 additions and 2 deletions

View File

@ -27,8 +27,14 @@ func (t *Taint) MatchTaint(taintToMatch Taint) bool {
return t.Key == taintToMatch.Key && t.Effect == taintToMatch.Effect
}
// taint.ToString() converts taint struct to string in format key=value:effect or key:effect.
// taint.ToString() converts taint struct to string in format '<key>=<value>:<effect>', '<key>=<value>:', '<key>:<effect>', or '<key>'.
func (t *Taint) ToString() string {
if len(t.Effect) == 0 {
if len(t.Value) == 0 {
return fmt.Sprintf("%v", t.Key)
}
return fmt.Sprintf("%v=%v:", t.Key, t.Value)
}
if len(t.Value) == 0 {
return fmt.Sprintf("%v:%v", t.Key, t.Effect)
}

View File

@ -38,6 +38,19 @@ func TestTaintToString(t *testing.T) {
},
expectedString: "foo:NoSchedule",
},
{
taint: &Taint{
Key: "foo",
},
expectedString: "foo",
},
{
taint: &Taint{
Key: "foo",
Value: "bar",
},
expectedString: "foo=bar:",
},
}
for i, tc := range testCases {

View File

@ -24,8 +24,14 @@ func (t *Taint) MatchTaint(taintToMatch *Taint) bool {
return t.Key == taintToMatch.Key && t.Effect == taintToMatch.Effect
}
// taint.ToString() converts taint struct to string in format key=value:effect or key:effect.
// taint.ToString() converts taint struct to string in format '<key>=<value>:<effect>', '<key>=<value>:', '<key>:<effect>', or '<key>'.
func (t *Taint) ToString() string {
if len(t.Effect) == 0 {
if len(t.Value) == 0 {
return fmt.Sprintf("%v", t.Key)
}
return fmt.Sprintf("%v=%v:", t.Key, t.Value)
}
if len(t.Value) == 0 {
return fmt.Sprintf("%v:%v", t.Key, t.Effect)
}

View File

@ -40,6 +40,19 @@ func TestTaintToString(t *testing.T) {
},
expectedString: "foo:NoSchedule",
},
{
taint: &Taint{
Key: "foo",
},
expectedString: "foo",
},
{
taint: &Taint{
Key: "foo",
Value: "bar",
},
expectedString: "foo=bar:",
},
}
for i, tc := range testCases {