Skip to content

Commit

Permalink
update test
Browse files Browse the repository at this point in the history
Signed-off-by: umit <[email protected]>
  • Loading branch information
umit committed Sep 16, 2024
1 parent 665634b commit ae02a9a
Showing 1 changed file with 19 additions and 3 deletions.
22 changes: 19 additions & 3 deletions go/utils/transform_utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@
package utils

import (
"reflect"
"testing"

"github.com/stretchr/testify/assert"
)

func TestConvertMapToKeyValueStringArray(t *testing.T) {
// Define test cases
testCases := []struct {
name string
key string
Expand All @@ -34,11 +36,25 @@ func TestConvertMapToKeyValueStringArray(t *testing.T) {
},
}

// Iterate through test cases.
for _, testCase := range testCases {
// Run each test case as a subtest.
t.Run(testCase.name, func(t *testing.T) {
// Call the function being tested.
actual := ConvertMapToKeyValueStringArray(testCase.key, testCase.args)
if !reflect.DeepEqual(actual, testCase.expected) {
t.Errorf("Expected result %v, but got %v", testCase.expected, actual)

// Check if the lengths of actual and expected slices match.
if len(actual) != len(testCase.expected) {
t.Errorf("Length mismatch. Expected %d, got %d", len(testCase.expected), len(actual))
}

// Check if the key is present in the actual result.
assert.Contains(t, actual, testCase.key, "The key should be present in the result")

// Check if all key-value pairs from the input map are present in the actual result.
for k, v := range testCase.args {
assert.Contains(t, actual, k, "The key from the input map should be present in the result")
assert.Contains(t, actual, v, "The value from the input map should be present in the result")
}
})
}
Expand Down

0 comments on commit ae02a9a

Please sign in to comment.