Skip to content

Commit

Permalink
added test
Browse files Browse the repository at this point in the history
  • Loading branch information
deemount committed Mar 23, 2024
1 parent a2a8c98 commit 80ae458
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions internals/utils/merge_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package utils_test

import (
"testing"
)

// TestMergeStringSliceToMap tests the MergeStringSliceToMap function.
func TestMergeStringSliceToMap(t *testing.T) {
t.Run("MergeStringSliceToMap", func(t *testing.T) {
t.Parallel()
m := make(map[string][]interface{})
k := "key"
v := []interface{}{"value"}
MergeStringSliceToMap(m, k, v)
if len(m) != 1 {
t.Errorf("Expected 1, got %d", len(m))
}
if len(m[k]) != 1 {
t.Errorf("Expected 1, got %d", len(m[k]))
}
if m[k][0] != "value" {
t.Errorf("Expected value, got %s", m[k][0])
}
})
}

func MergeStringSliceToMap(m map[string][]interface{}, k string, v []interface{}) {
if m[k] == nil {
m[k] = make([]interface{}, len(v))
copy(m[k], v)
} else {
m[k] = append(m[k], v...)
}
}

0 comments on commit 80ae458

Please sign in to comment.