-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Ref: 57, Longhorn-5614 Signed-off-by: Chin-Ya Huang <chin-ya.huang@suse.com>
- Loading branch information
Showing
1 changed file
with
73 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
package manager | ||
|
||
import ( | ||
"fmt" | ||
"reflect" | ||
"testing" | ||
|
||
corev1 "k8s.io/api/core/v1" | ||
) | ||
|
||
func TestParseToleration(t *testing.T) { | ||
type testCase struct { | ||
input string | ||
|
||
expectedToleration *corev1.Toleration | ||
expectError bool | ||
} | ||
testCases := map[string]testCase{ | ||
"valid key:NoSchedule": { | ||
input: "key:NoSchedule", | ||
expectedToleration: &corev1.Toleration{ | ||
Key: "key", | ||
Value: "", | ||
Operator: corev1.TolerationOpExists, | ||
Effect: corev1.TaintEffectNoSchedule, | ||
}, | ||
expectError: false, | ||
}, | ||
"valid key=value:NoExecute": { | ||
input: "key=value:NoExecute", | ||
expectedToleration: &corev1.Toleration{ | ||
Key: "key", | ||
Value: "value", | ||
Operator: corev1.TolerationOpEqual, | ||
Effect: corev1.TaintEffectNoExecute, | ||
}, | ||
expectError: false, | ||
}, | ||
"valid key=value:PreferNoSchedule": { | ||
input: "key=value:PreferNoSchedule", | ||
expectedToleration: &corev1.Toleration{ | ||
Key: "key", | ||
Value: "value", | ||
Operator: corev1.TolerationOpEqual, | ||
Effect: corev1.TaintEffectPreferNoSchedule, | ||
}, | ||
expectError: false, | ||
}, | ||
"invalid key:InvalidEffect": { | ||
input: "key:InvalidEffect", | ||
expectedToleration: nil, | ||
expectError: true, | ||
}, | ||
"invalid key=value=NoSchedule": { | ||
input: "key=value=NoSchedule", | ||
expectedToleration: nil, | ||
expectError: true, | ||
}, | ||
} | ||
|
||
for name, test := range testCases { | ||
fmt.Printf("testing %v\n", name) | ||
|
||
toleration, err := parseToleration(test.input) | ||
if !reflect.DeepEqual(toleration, test.expectedToleration) { | ||
t.Errorf("unexpected toleration:\nGot: %v\nWant: %v", toleration, test.expectedToleration) | ||
} | ||
|
||
if test.expectError && err == nil { | ||
t.Errorf("unexpected error: %v", err) | ||
} | ||
} | ||
} |