pbacsko commented on code in PR #881:
URL: https://github.com/apache/yunikorn-k8shim/pull/881#discussion_r1686701198


##########
pkg/common/resource_test.go:
##########
@@ -741,3 +766,119 @@ func TestParseResourceString(t *testing.T) {
                })
        }
 }
+
+func TestGetResource(t *testing.T) {
+       tests := []struct {
+               name        string
+               resMap      map[string]string
+               expectedRes map[string]int64
+       }{
+               {
+                       name:        "empty resMap",
+                       resMap:      map[string]string{},
+                       expectedRes: map[string]int64{},
+               },
+               {
+                       name: "single resource",
+                       resMap: map[string]string{
+                               v1.ResourceCPU.String(): "100m",
+                       },
+                       expectedRes: map[string]int64{
+                               siCommon.CPU: 100,
+                       },
+               },
+               {
+                       name: "multiple resources",
+                       resMap: map[string]string{
+                               v1.ResourceCPU.String():    "1",
+                               v1.ResourceMemory.String(): "1G",
+                       },
+                       expectedRes: map[string]int64{
+                               siCommon.CPU:    1000,
+                               siCommon.Memory: 1000 * 1000 * 1000,
+                       },
+               },
+               {
+                       name: "invalid cpu resources",
+                       resMap: map[string]string{
+                               v1.ResourceCPU.String(): "xyz",
+                       },
+                       expectedRes: nil,
+               },
+               {
+                       name: "invalid memery resources",
+                       resMap: map[string]string{
+                               v1.ResourceMemory.String(): "64MiB",
+                       },
+                       expectedRes: nil,
+               },
+       }
+
+       for _, tt := range tests {
+               t.Run(tt.name, func(t *testing.T) {
+                       actualRes := GetResource(tt.resMap)
+                       if tt.expectedRes == nil {
+                               assert.Equal(t, actualRes == nil, true)

Review Comment:
   Nit: just `assert.Assert(t, actualRes == nil)`



##########
pkg/common/resource_test.go:
##########
@@ -741,3 +766,119 @@ func TestParseResourceString(t *testing.T) {
                })
        }
 }
+
+func TestGetResource(t *testing.T) {
+       tests := []struct {
+               name        string
+               resMap      map[string]string
+               expectedRes map[string]int64
+       }{
+               {
+                       name:        "empty resMap",
+                       resMap:      map[string]string{},
+                       expectedRes: map[string]int64{},
+               },
+               {
+                       name: "single resource",
+                       resMap: map[string]string{
+                               v1.ResourceCPU.String(): "100m",
+                       },
+                       expectedRes: map[string]int64{
+                               siCommon.CPU: 100,
+                       },
+               },
+               {
+                       name: "multiple resources",
+                       resMap: map[string]string{
+                               v1.ResourceCPU.String():    "1",
+                               v1.ResourceMemory.String(): "1G",
+                       },
+                       expectedRes: map[string]int64{
+                               siCommon.CPU:    1000,
+                               siCommon.Memory: 1000 * 1000 * 1000,
+                       },
+               },
+               {
+                       name: "invalid cpu resources",
+                       resMap: map[string]string{
+                               v1.ResourceCPU.String(): "xyz",
+                       },
+                       expectedRes: nil,
+               },
+               {
+                       name: "invalid memery resources",

Review Comment:
   Typo: "memery"



##########
pkg/common/si_helper_test.go:
##########
@@ -56,6 +57,21 @@ func TestCreateReleaseRequestForTask(t *testing.T) {
        assert.Equal(t, 
request.Releases.AllocationAsksToRelease[0].ApplicationID, "app01")
        assert.Equal(t, 
request.Releases.AllocationAsksToRelease[0].AllocationKey, "task01")
        assert.Equal(t, 
request.Releases.AllocationAsksToRelease[0].PartitionName, "default")
+       assert.Equal(t, 
request.Releases.AllocationAsksToRelease[0].TerminationType, 
si.TerminationType_UNKNOWN_TERMINATION_TYPE)
+
+       request = CreateReleaseRequestForTask("app01", "task01", "task01", 
"default", "UNKNOW")

Review Comment:
   nit: "UNKNOW" -> "UNKNOWN"



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