Skip to content

Commit

Permalink
[YUNIKORN-2045] unify DeepEqual (#682)
Browse files Browse the repository at this point in the history
Closes: #682

Signed-off-by: Peter Bacsko <[email protected]>
  • Loading branch information
steinsgateted authored and pbacsko committed Oct 23, 2023
1 parent c3f3061 commit 8997cc2
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 31 deletions.
2 changes: 1 addition & 1 deletion pkg/common/configs/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1721,7 +1721,7 @@ func TestGetConfigurationString(t *testing.T) {
}
for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
assert.DeepEqual(t, tc.expectedConfig, GetConfigurationString(tc.requestBytes))
assert.Equal(t, tc.expectedConfig, GetConfigurationString(tc.requestBytes))
})
}
}
Expand Down
38 changes: 19 additions & 19 deletions pkg/scheduler/objects/queue_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1636,7 +1636,7 @@ func TestGetPartitionQueueDAOInfo(t *testing.T) {

// test properties
root.properties = getProperties()
assert.Assert(t, reflect.DeepEqual(root.properties, root.GetPartitionQueueDAOInfo().Properties))
assert.DeepEqual(t, root.properties, root.GetPartitionQueueDAOInfo().Properties)

// test template
root.template, err = template.FromConf(&configs.ChildTemplate{
Expand All @@ -1647,7 +1647,7 @@ func TestGetPartitionQueueDAOInfo(t *testing.T) {
},
})
assert.NilError(t, err)
assert.Assert(t, reflect.DeepEqual(root.template.GetProperties(), root.GetPartitionQueueDAOInfo().TemplateInfo.Properties))
assert.DeepEqual(t, root.template.GetProperties(), root.GetPartitionQueueDAOInfo().TemplateInfo.Properties)
assert.DeepEqual(t, root.template.GetMaxResource().DAOMap(), root.template.GetMaxResource().DAOMap())
assert.DeepEqual(t, root.template.GetGuaranteedResource().DAOMap(), root.template.GetGuaranteedResource().DAOMap())

Expand Down Expand Up @@ -1712,29 +1712,29 @@ func TestSetResources(t *testing.T) {

expectedGuaranteedResource, err := resources.NewResourceFromConf(guaranteedResource)
assert.NilError(t, err, "failed to parse resource: %v", err)
assert.Assert(t, reflect.DeepEqual(queue.guaranteedResource, expectedGuaranteedResource))
assert.DeepEqual(t, queue.guaranteedResource, expectedGuaranteedResource)

expectedMaxResource, err := resources.NewResourceFromConf(maxResource)
assert.NilError(t, err, "failed to parse resource: %v", err)
assert.Assert(t, reflect.DeepEqual(queue.maxResource, expectedMaxResource))
assert.DeepEqual(t, queue.maxResource, expectedMaxResource)

// case 1: empty resource won't change the resources
err = queue.setResources(configs.Resources{
Guaranteed: make(map[string]string),
Max: make(map[string]string),
})
assert.NilError(t, err, "failed to set resources: %v", err)
assert.Assert(t, reflect.DeepEqual(queue.guaranteedResource, expectedGuaranteedResource))
assert.Assert(t, reflect.DeepEqual(queue.maxResource, expectedMaxResource))
assert.DeepEqual(t, queue.guaranteedResource, expectedGuaranteedResource)
assert.DeepEqual(t, queue.maxResource, expectedMaxResource)

// case 2: zero resource won't change the resources
err = queue.setResources(configs.Resources{
Guaranteed: getZeroResourceConf(),
Max: getZeroResourceConf(),
})
assert.NilError(t, err, "failed to set resources: %v", err)
assert.Assert(t, reflect.DeepEqual(queue.guaranteedResource, expectedGuaranteedResource))
assert.Assert(t, reflect.DeepEqual(queue.maxResource, expectedMaxResource))
assert.DeepEqual(t, queue.guaranteedResource, expectedGuaranteedResource)
assert.DeepEqual(t, queue.maxResource, expectedMaxResource)
}

func TestPreemptingResource(t *testing.T) {
Expand Down Expand Up @@ -1960,9 +1960,9 @@ func TestSetTemplate(t *testing.T) {
assert.NilError(t, err, "failed to parse resource: %v", err)

checkTemplate := func(queue *Queue) {
assert.Assert(t, reflect.DeepEqual(queue.template.GetProperties(), properties))
assert.Assert(t, reflect.DeepEqual(queue.template.GetGuaranteedResource(), expectedGuaranteedResource))
assert.Assert(t, reflect.DeepEqual(queue.template.GetMaxResource(), expectedMaxResource))
assert.DeepEqual(t, queue.template.GetProperties(), properties)
assert.DeepEqual(t, queue.template.GetGuaranteedResource(), expectedGuaranteedResource)
assert.DeepEqual(t, queue.template.GetMaxResource(), expectedMaxResource)
}

// case 0: normal case
Expand Down Expand Up @@ -2003,9 +2003,9 @@ func TestApplyTemplate(t *testing.T) {
assert.NilError(t, err, "failed to create basic queue queue: %v", err)
leaf.applyTemplate(childTemplate)
assert.Assert(t, leaf.template == nil)
assert.Assert(t, reflect.DeepEqual(leaf.properties, childTemplate.GetProperties()))
assert.Assert(t, reflect.DeepEqual(leaf.guaranteedResource, childTemplate.GetGuaranteedResource()))
assert.Assert(t, reflect.DeepEqual(leaf.maxResource, childTemplate.GetMaxResource()))
assert.DeepEqual(t, leaf.properties, childTemplate.GetProperties())
assert.DeepEqual(t, leaf.guaranteedResource, childTemplate.GetGuaranteedResource())
assert.DeepEqual(t, leaf.maxResource, childTemplate.GetMaxResource())

// case 1: zero resource template generates nil resource
leaf2, err := createManagedQueueWithProps(nil, "tmp", false, nil, nil)
Expand Down Expand Up @@ -2151,7 +2151,7 @@ func TestNewConfiguredQueue(t *testing.T) {
assert.Equal(t, parent.QueuePath, "parent_queue")
assert.Equal(t, parent.isManaged, true)
assert.Equal(t, parent.maxRunningApps, uint64(32))
assert.Assert(t, reflect.DeepEqual(properties, parent.template.GetProperties()))
assert.DeepEqual(t, properties, parent.template.GetProperties())
assert.Assert(t, resources.Equals(resourceStruct, parent.template.GetMaxResource()))
assert.Assert(t, resources.Equals(resourceStruct, parent.template.GetGuaranteedResource()))

Expand All @@ -2169,7 +2169,7 @@ func TestNewConfiguredQueue(t *testing.T) {
assert.NilError(t, err, "failed to create queue: %v", err)
assert.Equal(t, childLeaf.QueuePath, "parent_queue.leaf_queue")
assert.Assert(t, childLeaf.template == nil)
assert.Assert(t, reflect.DeepEqual(childLeaf.properties, parent.template.GetProperties()))
assert.DeepEqual(t, childLeaf.properties, parent.template.GetProperties())
assert.Assert(t, resources.Equals(childLeaf.maxResource, parent.template.GetMaxResource()))
assert.Assert(t, resources.Equals(childLeaf.guaranteedResource, parent.template.GetGuaranteedResource()))

Expand Down Expand Up @@ -2237,9 +2237,9 @@ func TestNewDynamicQueue(t *testing.T) {
childLeaf, err := NewDynamicQueue("leaf", true, parent)
assert.NilError(t, err, "failed to create dynamic queue: %v", err)
assert.Assert(t, childLeaf.template == nil)
assert.Assert(t, reflect.DeepEqual(childLeaf.properties, parent.template.GetProperties()))
assert.Assert(t, reflect.DeepEqual(childLeaf.maxResource, parent.template.GetMaxResource()))
assert.Assert(t, reflect.DeepEqual(childLeaf.guaranteedResource, parent.template.GetGuaranteedResource()))
assert.DeepEqual(t, childLeaf.properties, parent.template.GetProperties())
assert.DeepEqual(t, childLeaf.maxResource, parent.template.GetMaxResource())
assert.DeepEqual(t, childLeaf.guaranteedResource, parent.template.GetGuaranteedResource())
assert.Assert(t, childLeaf.prioritySortEnabled)
assert.Equal(t, childLeaf.priorityPolicy, policies.DefaultPriorityPolicy)
assert.Equal(t, childLeaf.preemptionPolicy, policies.DefaultPreemptionPolicy)
Expand Down
13 changes: 6 additions & 7 deletions pkg/scheduler/objects/template/template_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
package template

import (
"reflect"
"strconv"
"testing"
"time"
Expand Down Expand Up @@ -51,14 +50,14 @@ func getResource(t *testing.T) *resources.Resource {

func checkMembers(t *testing.T, template *Template, properties map[string]string, maxResource *resources.Resource, guaranteedResource *resources.Resource) {
// test inner members
assert.Assert(t, reflect.DeepEqual(template.properties, properties))
assert.Assert(t, reflect.DeepEqual(template.maxResource, maxResource))
assert.Assert(t, reflect.DeepEqual(template.guaranteedResource, guaranteedResource))
assert.DeepEqual(t, template.properties, properties)
assert.DeepEqual(t, template.maxResource, maxResource)
assert.DeepEqual(t, template.guaranteedResource, guaranteedResource)

// test all getters
assert.Assert(t, reflect.DeepEqual(template.GetProperties(), properties))
assert.Assert(t, reflect.DeepEqual(template.GetMaxResource(), maxResource))
assert.Assert(t, reflect.DeepEqual(template.GetGuaranteedResource(), guaranteedResource))
assert.DeepEqual(t, template.GetProperties(), properties)
assert.DeepEqual(t, template.GetMaxResource(), maxResource)
assert.DeepEqual(t, template.GetGuaranteedResource(), guaranteedResource)
}

func TestNewTemplate(t *testing.T) {
Expand Down
1 change: 0 additions & 1 deletion pkg/scheduler/policies/nodesorting_policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,3 @@ func SortingPolicyFromString(str string) (SortingPolicy, error) {
return FairnessPolicy, fmt.Errorf("undefined policy: %s", str)
}
}

1 change: 0 additions & 1 deletion pkg/scheduler/policies/nodesorting_policy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,4 +63,3 @@ func TestSortingPolicyToString(t *testing.T) {
}
}
}

4 changes: 2 additions & 2 deletions pkg/webservice/handlers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -509,7 +509,7 @@ func TestGetConfigYAML(t *testing.T) {
assert.NilError(t, err, "failed to unmarshal config from response body (updated config)")
assert.Equal(t, conf.Partitions[0].NodeSortPolicy.Type, "binpacking", "node sort policy not updated")
assert.Assert(t, startConfSum != conf.Checksum, "checksums did not change in output")
assert.Assert(t, reflect.DeepEqual(conf.Extra, updatedExtraConf), "extra config did not change")
assert.DeepEqual(t, conf.Extra, updatedExtraConf)

// reset extra config map
configs.SetConfigMap(map[string]string{})
Expand Down Expand Up @@ -540,7 +540,7 @@ func TestGetConfigJSON(t *testing.T) {
assert.NilError(t, err, "failed to unmarshal config from response body (json, updated config)")
assert.Assert(t, startConfSum != conf.Checksum, "checksums did not change in json output: %s, %s", startConfSum, conf.Checksum)
assert.Equal(t, conf.Partitions[0].NodeSortPolicy.Type, "binpacking", "node sort policy not updated (json)")
assert.Assert(t, reflect.DeepEqual(conf.Extra, updatedExtraConf), "extra config did not change")
assert.DeepEqual(t, conf.Extra, updatedExtraConf)

// reset extra config map
configs.SetConfigMap(map[string]string{})
Expand Down

0 comments on commit 8997cc2

Please sign in to comment.