kingamarton commented on a change in pull request #239:
URL: 
https://github.com/apache/incubator-yunikorn-k8shim/pull/239#discussion_r592236442



##########
File path: pkg/cache/placeholder_test.go
##########
@@ -68,6 +68,45 @@ func TestNewPlaceholder(t *testing.T) {
        assert.Equal(t, holder.String(), "appID: app01, taskGroup: 
test-group-1, podName: test/ph-name")
 }
 
+func TestNewPlaceholderWithLabelsAndAnnotations(t *testing.T) {
+       const (
+               appID     = "app01"
+               queue     = "root.default"
+               namespace = "test"
+       )
+       mockedSchedulerAPI := newMockSchedulerAPI()
+       app := NewApplication(appID, queue,
+               "bob", map[string]string{constants.AppTagNamespace: namespace}, 
mockedSchedulerAPI)
+       app.setTaskGroups([]v1alpha1.TaskGroup{
+               {
+                       Name:      "test-group-1",
+                       MinMember: 10,
+                       MinResource: map[string]resource.Quantity{
+                               "cpu":    resource.MustParse("500m"),
+                               "memory": resource.MustParse("1024M"),
+                       },
+                       Labels: map[string]string{
+                               "labelKey0": "labelKeyValue0",
+                               "labelKey1": "labelKeyValue1",
+                       },
+                       Annotations: map[string]string{
+                               "annotationKey0": "annotationValue0",
+                               "annotationKey1": "annotationValue1",
+                               "annotationKey2": "annotationValue2",
+                       },
+               },
+       })
+
+       holder := newPlaceholder("ph-name", app, app.taskGroups[0])
+       assert.Equal(t, len(holder.pod.Labels), 4)
+       assert.Equal(t, len(holder.pod.Annotations), 5)
+       assert.Equal(t, holder.pod.Labels["labelKey0"], "labelKeyValue0")
+       assert.Equal(t, holder.pod.Labels["labelKey1"], "labelKeyValue1")
+       assert.Equal(t, holder.pod.Annotations["annotationKey0"], 
"annotationValue0")
+       assert.Equal(t, holder.pod.Annotations["annotationKey1"], 
"annotationValue1")
+       assert.Equal(t, holder.pod.Annotations["annotationKey2"], 
"annotationValue2")

Review comment:
       nit: we can compare two maps in one line using assert.DeepEqual. With 
that we can make the comparison in 2 lines instead of 7

##########
File path: pkg/common/utils/utils_test.go
##########
@@ -331,3 +331,39 @@ func TestGetApplicationIDFromPod(t *testing.T) {
                })
        }
 }
+
+func TestMergeMaps(t *testing.T) {
+       result := MergeMaps(nil, nil)
+       assert.Assert(t, result == nil)
+
+       result = MergeMaps(nil, map[string]string{"a": "b"})
+       assert.Assert(t, result != nil)
+       assert.Equal(t, len(result), 1)
+       assert.Equal(t, result["a"], "b")
+
+       result = MergeMaps(map[string]string{"a": "b"}, nil)
+       assert.Assert(t, result != nil)
+       assert.Equal(t, len(result), 1)
+       assert.Equal(t, result["a"], "b")
+
+       result = MergeMaps(map[string]string{"a": "a1"}, map[string]string{"a": 
"a2"})
+       assert.Assert(t, result != nil)
+       assert.Equal(t, len(result), 1)
+       assert.Equal(t, result["a"], "a2")
+
+       result = MergeMaps(map[string]string{
+               "a": "a1",
+               "b": "b1",
+               "c": "c1",
+       }, map[string]string{
+               "a": "a2",
+               "b": "b2",
+               "d": "d2",
+       })
+       assert.Assert(t, result != nil)
+       assert.Equal(t, len(result), 4)
+       assert.Equal(t, result["a"], "a2")
+       assert.Equal(t, result["b"], "b2")
+       assert.Equal(t, result["c"], "c1")
+       assert.Equal(t, result["d"], "d2")
+}

Review comment:
       nit: if it is possible in go it is suggested to write table driven 
tests. It is more clear and elegant.
   ```
   testCases := []struct {
                name string
                map1       map[string]string
                map2 map[string]string
                expectedResult map[string]string
        }{
                {"Nil maps", nil, nil, nil},
                     ...... <create here the other cases>
        }
        for _, tc := range testCases {
                t.Run(tc.name, func(t *testing.T) {
                        assert.DeepEqual(t, MergeMaps(tc.map1, tc.map2), 
tc.expectedResult)
                })
        }
   ```




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

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to