0yukali0 commented on code in PR #474:
URL: https://github.com/apache/yunikorn-k8shim/pull/474#discussion_r1024221295
##########
pkg/common/utils/utils_test.go:
##########
@@ -696,3 +699,356 @@ func TestNeedRecovery(t *testing.T) {
})
}
}
+func TestGetTaskGroupFromPodSpec(t *testing.T) {
+ pod := &v1.Pod{
+ TypeMeta: metav1.TypeMeta{
+ Kind: "Pod",
+ APIVersion: "v1",
+ },
+ ObjectMeta: metav1.ObjectMeta{
+ Name: "pod-01",
+ UID: "UID-01",
+ Annotations: map[string]string{
+ constants.AnnotationTaskGroupName:
"test-task-group",
+ },
+ },
+ }
+
+ assert.Equal(t, GetTaskGroupFromPodSpec(pod), "test-task-group")
+
+ pod = &v1.Pod{
+ TypeMeta: metav1.TypeMeta{
+ Kind: "Pod",
+ APIVersion: "v1",
+ },
+ ObjectMeta: metav1.ObjectMeta{
+ Name: "pod-01",
+ UID: "UID-01",
+ },
+ }
+
+ assert.Equal(t, GetTaskGroupFromPodSpec(pod), "")
+}
+
+// nolint: funlen
+func TestGetTaskGroupFromAnnotation(t *testing.T) {
+ // correct json
+ testGroup := `
+ [
+ {
+ "name": "test-group-1",
+ "minMember": 10,
+ "minResource": {
+ "cpu": 1,
+ "memory": "2Gi"
+ },
+ "nodeSelector": {
+ "test": "testnode",
+ "locate": "west"
+ },
+ "tolerations": [
+ {
+ "key": "key",
+ "operator": "Equal",
+ "value": "value",
+ "effect": "NoSchedule"
+ }
+ ]
+ },
+ {
+ "name": "test-group-2",
+ "minMember": 5,
+ "minResource": {
+ "cpu": 2,
+ "memory": "4Gi"
+ }
+ }
+ ]`
+ testGroup2 := `
+ [
+ {
+ "name": "test-group-3",
+ "minMember": 3,
+ "minResource": {
+ "cpu": 2,
+ "memory": "1Gi"
+ }
+ }
+ ]`
+ // Error json
+ testGroupErr := `
+ [
+ {
+ "name": "test-group-err-1",
+ "minMember": "ERR",
+ "minResource": {
+ "cpu": "ERR",
+ "memory": "ERR"
+ },
+ }
+ ]`
+ // without name
+ testGroupErr2 := `
+ [
+ {
+ "minMember": 3,
+ "minResource": {
+ "cpu": 2,
+ "memory": "1Gi"
+ }
+ }
+ ]`
+ // without minMember
+ testGroupErr3 := `
+ [
+ {
+ "name": "test-group-err-2",
+ "minResource": {
+ "cpu": 2,
+ "memory": "1Gi"
+ }
+ }
+ ]`
+ // withot minResource
+ testGroupErr4 := `
+ [
+ {
+ "name": "test-group-err-4",
+ "minMember": 3,
+ }
+ ]`
+ // negative minMember
+ testGroupErr5 := `
+ [
+ {
+ "name": "test-group-err-5",
+ "minMember": -100,
Review Comment:
This example is designed for negative minMember, However this case is
classified to parsing error when I tested
So we should remove the comma to improve the coverage, or this err will be
classified to parsing error.
```
change "minMember": -100, to "minMember": -100
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]