You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@yunikorn.apache.org by pb...@apache.org on 2023/12/04 15:08:03 UTC
(yunikorn-k8shim) branch master updated: [YUNIKORN-563] test: improve unit test assertion (#739)
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-k8shim.git
The following commit(s) were added to refs/heads/master by this push:
new ff939a5f [YUNIKORN-563] test: improve unit test assertion (#739)
ff939a5f is described below
commit ff939a5f43e1f6d2a0a07f1003eb5c0c1229f865
Author: Cliff Su <st...@yahoo.com.tw>
AuthorDate: Mon Dec 4 16:07:54 2023 +0100
[YUNIKORN-563] test: improve unit test assertion (#739)
Closes: #739
Signed-off-by: Peter Bacsko <pb...@cloudera.com>
---
pkg/cache/placeholder_test.go | 12 ++++--
pkg/common/utils/utils_test.go | 98 ++++++++++++++++++++++++++++--------------
2 files changed, 75 insertions(+), 35 deletions(-)
diff --git a/pkg/cache/placeholder_test.go b/pkg/cache/placeholder_test.go
index 17ab5049..8dee656b 100644
--- a/pkg/cache/placeholder_test.go
+++ b/pkg/cache/placeholder_test.go
@@ -140,10 +140,16 @@ func TestNewPlaceholderWithLabelsAndAnnotations(t *testing.T) {
app.setTaskGroupsDefinition(string(marshalledTaskGroups))
holder := newPlaceholder("ph-name", app, app.taskGroups[0])
- assert.Equal(t, len(holder.pod.Labels), 5)
+
+ assert.DeepEqual(t, holder.pod.Labels, map[string]string{
+ "applicationId": "app01",
+ "labelKey0": "labelKeyValue0",
+ "labelKey1": "labelKeyValue1",
+ "placeholder": "true",
+ "queue": "root.default",
+ })
+
assert.Equal(t, len(holder.pod.Annotations), 6)
- 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")
diff --git a/pkg/common/utils/utils_test.go b/pkg/common/utils/utils_test.go
index 7f966ae1..77799999 100644
--- a/pkg/common/utils/utils_test.go
+++ b/pkg/common/utils/utils_test.go
@@ -632,39 +632,73 @@ func TestGenerateApplicationID(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")
+ testCases := []struct {
+ name string
+ input1 map[string]string
+ input2 map[string]string
+ expected map[string]string
+ }{
+ {
+ name: "Both inputs nil",
+ input1: nil,
+ input2: nil,
+ expected: nil,
+ },
+ {
+ name: "First input nil, Second input not nil",
+ input1: nil,
+ input2: map[string]string{"a": "b"},
+ expected: map[string]string{
+ "a": "b",
+ },
+ },
+ {
+ name: "First input not nil, Second input nil",
+ input1: map[string]string{"a": "b"},
+ input2: nil,
+ expected: map[string]string{
+ "a": "b",
+ },
+ },
+ {
+ name: "Merge with existing key",
+ input1: map[string]string{
+ "a": "a1",
+ },
+ input2: map[string]string{
+ "a": "a2",
+ },
+ expected: map[string]string{
+ "a": "a2",
+ },
+ },
+ {
+ name: "Merge with additional keys",
+ input1: map[string]string{
+ "a": "a1",
+ "b": "b1",
+ "c": "c1",
+ },
+ input2: map[string]string{
+ "a": "a2",
+ "b": "b2",
+ "d": "d2",
+ },
+ expected: map[string]string{
+ "a": "a2",
+ "b": "b2",
+ "c": "c1",
+ "d": "d2",
+ },
+ },
+ }
- 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")
+ for _, tc := range testCases {
+ t.Run(tc.name, func(t *testing.T) {
+ result := MergeMaps(tc.input1, tc.input2)
+ assert.DeepEqual(t, result, tc.expected)
+ })
+ }
}
func TestGetUserFromPodLabel(t *testing.T) {
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@yunikorn.apache.org
For additional commands, e-mail: issues-help@yunikorn.apache.org