0yukali0 commented on code in PR #474:
URL: https://github.com/apache/yunikorn-k8shim/pull/474#discussion_r1024219632


##########
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,

Review Comment:
   This example is designed for nil minMenber.
   So we should remove the comma, or this err will be classified to parsing 
error.
   ```
   change "minMember": 3,  to "minMember": 3 
   ```
   
   However, there is not an exception handling  for empty minResource in the 
GetTaskGroupsFromAnnotation function.
   Maybe we need to add a exception handling for nil minResource in the 
GetTaskGroupsFromAnnotation.



-- 
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]

Reply via email to