chenyulin0719 commented on code in PR #900:
URL: https://github.com/apache/yunikorn-k8shim/pull/900#discussion_r1732380596


##########
pkg/common/utils/utils_test.go:
##########
@@ -723,6 +724,212 @@ func TestGetApplicationIDFromPod(t *testing.T) {
        }
 }
 
+func TestCheckAppIdInPod(t *testing.T) {
+       mismatchError := errors.New("pod has inconsistent application ID")
+       tests := []struct {
+               name     string
+               pod      *v1.Pod
+               expected error
+       }{
+               {
+                       name: "consistent app ID",
+                       pod: &v1.Pod{
+                               ObjectMeta: metav1.ObjectMeta{
+                                       Labels: map[string]string{
+                                               
constants.CanonicalLabelApplicationID: "app-123",
+                                               constants.SparkLabelAppID:      
       "app-123",
+                                               constants.LabelApplicationID:   
       "app-123",
+                                       },
+                                       Annotations: map[string]string{
+                                               
constants.AnnotationApplicationID: "app-123",
+                                       },
+                               },
+                       },
+                       expected: nil,
+               },
+               {
+                       name: "inconsistent app ID in labels",
+                       pod: &v1.Pod{
+                               ObjectMeta: metav1.ObjectMeta{
+                                       Labels: map[string]string{
+                                               
constants.CanonicalLabelApplicationID: "app-123",
+                                               constants.SparkLabelAppID:      
       "app-456",
+                                       },
+                               },
+                       },
+                       expected: mismatchError,
+               },
+               {
+                       name: "inconsistent app ID between label and 
annotation",
+                       pod: &v1.Pod{
+                               ObjectMeta: metav1.ObjectMeta{
+                                       Labels: map[string]string{
+                                               
constants.CanonicalLabelApplicationID: "app-123",
+                                       },
+                                       Annotations: map[string]string{
+                                               
constants.AnnotationApplicationID: "app-456",
+                                       },
+                               },
+                       },
+                       expected: mismatchError,
+               },
+       }
+       for _, tt := range tests {
+               t.Run(tt.name, func(t *testing.T) {
+                       err := CheckAppIdInPod(tt.pod)
+                       if err != nil {
+                               assert.ErrorContains(t, err, 
tt.expected.Error())
+                       } else {
+                               assert.NilError(t, err)
+                       }
+               })
+       }
+}
+
+func TestCheckQueueNameInPod(t *testing.T) {
+       mismatchError := errors.New("pod has inconsistent queue name")
+       tests := []struct {
+               name     string
+               pod      *v1.Pod
+               expected error
+       }{
+               {
+                       name: "consistent queue name",
+                       pod: &v1.Pod{
+                               ObjectMeta: metav1.ObjectMeta{
+                                       Labels: map[string]string{
+                                               
constants.CanonicalLabelQueueName: "root.a",
+                                               constants.LabelQueueName:       
   "root.a",
+                                       },
+                                       Annotations: map[string]string{
+                                               constants.AnnotationQueueName: 
"root.a",
+                                       },
+                               },
+                       },
+                       expected: nil,
+               },
+               {
+                       name: "inconsistent app ID in labels",
+                       pod: &v1.Pod{
+                               ObjectMeta: metav1.ObjectMeta{
+                                       Labels: map[string]string{
+                                               
constants.CanonicalLabelQueueName: "root.a",
+                                               constants.LabelQueueName:       
   "root.b",
+                                       },
+                               },
+                       },
+                       expected: mismatchError,
+               },
+               {
+                       name: "inconsistent app ID between label and 
annotation",
+                       pod: &v1.Pod{
+                               ObjectMeta: metav1.ObjectMeta{
+                                       Labels: map[string]string{
+                                               
constants.CanonicalLabelQueueName: "root.a",
+                                       },
+                                       Annotations: map[string]string{
+                                               constants.AnnotationQueueName: 
"root.b",
+                                       },
+                               },
+                       },
+                       expected: mismatchError,
+               },
+       }
+       for _, tt := range tests {
+               t.Run(tt.name, func(t *testing.T) {
+                       err := CheckAppIdInPod(tt.pod)

Review Comment:
   Sorry, it's was a typo. Thanks for pointing it out. Fixed it in the new 
commits.



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