This is an automated email from the ASF dual-hosted git repository.

pbacsko pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/yunikorn-core.git


The following commit(s) were added to refs/heads/master by this push:
     new a1a10f8e [YUNIKORN-2297] Update the unit test for CheckQueuesStructure 
(#860)
a1a10f8e is described below

commit a1a10f8e8621288c6919aad269540b44c6e20227
Author: YUN SUN <[email protected]>
AuthorDate: Tue Apr 30 15:39:04 2024 +0200

    [YUNIKORN-2297] Update the unit test for CheckQueuesStructure (#860)
    
    Closes: #860
    
    Signed-off-by: Peter Bacsko <[email protected]>
---
 pkg/common/configs/configvalidator_test.go | 102 +++++++++++++++++++++++++++++
 1 file changed, 102 insertions(+)

diff --git a/pkg/common/configs/configvalidator_test.go 
b/pkg/common/configs/configvalidator_test.go
index 99001dff..8ddf1d3c 100644
--- a/pkg/common/configs/configvalidator_test.go
+++ b/pkg/common/configs/configvalidator_test.go
@@ -1910,3 +1910,105 @@ func TestCheckLimitsStructure(t *testing.T) {
        assert.Equal(t, len(partitionConfig.Queues[0].Limits), 0)
        assert.Equal(t, len(partitionConfig.Limits), 0)
 }
+
+func TestCheckQueuesStructure(t *testing.T) {
+       negativeResourceMap := map[string]string{"memory": "-50", "vcores": 
"33"}
+       testCases := []struct {
+               name             string
+               partition        *PartitionConfig
+               errorExpected    bool
+               expectedErrorMsg string
+               validateFunc     func(t *testing.T, partition *PartitionConfig)
+       }{
+               {
+                       name:             "No Queues Configured",
+                       partition:        &PartitionConfig{Queues: nil},
+                       errorExpected:    true,
+                       expectedErrorMsg: "queue config is not set",
+               },
+               {
+                       name: "Single Root Queue",
+                       partition: &PartitionConfig{
+                               Queues: []QueueConfig{
+                                       {Name: "root", Parent: true},
+                               },
+                       },
+                       errorExpected: false,
+                       validateFunc: func(t *testing.T, p *PartitionConfig) {
+                               assert.Equal(t, 1, len(p.Queues), "There should 
be exactly one queue")
+                               assert.Equal(t, "root", p.Queues[0].Name, "Root 
queue should be named 'root'")
+                               assert.Assert(t, p.Queues[0].Parent, "Root 
queue should be a parent")
+                       },
+               },
+               {
+                       name: "Single Non-Root Queue",
+                       partition: &PartitionConfig{
+                               Queues: []QueueConfig{
+                                       {Name: "non-root"},
+                               },
+                       },
+                       errorExpected: false,
+                       validateFunc: func(t *testing.T, p *PartitionConfig) {
+                               assert.Equal(t, 1, len(p.Queues), "There should 
be exactly one queue in the new root")
+                               assert.Equal(t, "root", p.Queues[0].Name, "Root 
queue should be named 'root'")
+                               assert.Assert(t, p.Queues[0].Parent, "Root 
queue should be a parent")
+                               assert.Equal(t, 1, len(p.Queues[0].Queues), 
"New root queue should contain the non-root queue")
+                       },
+               },
+               {
+                       name: "Multiple Top-Level Queues",
+                       partition: &PartitionConfig{
+                               Queues: []QueueConfig{
+                                       {Name: "queue1"},
+                                       {Name: "queue2"},
+                               },
+                       },
+                       errorExpected: false,
+                       validateFunc: func(t *testing.T, p *PartitionConfig) {
+                               assert.Equal(t, 1, len(p.Queues), "There should 
be exactly one queue in the new root")
+                               assert.Equal(t, "root", p.Queues[0].Name, "Root 
queue should be named 'root'")
+                               assert.Assert(t, p.Queues[0].Parent, "Root 
queue should be a parent")
+                               assert.Equal(t, 2, len(p.Queues[0].Queues), 
"New root queue should contain both top-level queues")
+                       },
+               },
+               {
+                       name: "Root Queue With Guaranteed Resources",
+                       partition: &PartitionConfig{
+                               Queues: []QueueConfig{
+                                       {
+                                               Name:      "root",
+                                               Parent:    true,
+                                               Resources: 
Resources{Guaranteed: negativeResourceMap}},
+                               },
+                       },
+                       errorExpected:    true,
+                       expectedErrorMsg: "root queue must not have resource 
limits set",
+               },
+               {
+                       name: "Root Queue With Max Resources",
+                       partition: &PartitionConfig{
+                               Queues: []QueueConfig{
+                                       {
+                                               Name:      "root",
+                                               Parent:    true,
+                                               Resources: Resources{Max: 
negativeResourceMap}},
+                               },
+                       },
+                       errorExpected:    true,
+                       expectedErrorMsg: "root queue must not have resource 
limits set",
+               },
+       }
+       for _, tc := range testCases {
+               t.Run(tc.name, func(t *testing.T) {
+                       err := checkQueuesStructure(tc.partition)
+                       if tc.errorExpected {
+                               assert.ErrorContains(t, err, 
tc.expectedErrorMsg, "Error message mismatch")
+                       } else {
+                               assert.NilError(t, err, "No error is expected")
+                               if tc.validateFunc != nil {
+                                       tc.validateFunc(t, tc.partition)
+                               }
+                       }
+               })
+       }
+}


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to