github.com/khulnasoft/cli@v0.0.0-20240402070845-01bcad7beefa/internal/test/strings.go (about)

     1  package test
     2  
     3  import (
     4  	"strings"
     5  	"testing"
     6  
     7  	"gotest.tools/v3/assert"
     8  	is "gotest.tools/v3/assert/cmp"
     9  )
    10  
    11  // CompareMultipleValues compares comma-separated values, whatever the order is
    12  func CompareMultipleValues(t *testing.T, value, expected string) {
    13  	t.Helper()
    14  	// comma-separated values means probably a map input, which won't
    15  	// be guaranteed to have the same order as our expected value
    16  	// We'll create maps and use reflect.DeepEquals to check instead:
    17  	entriesMap := make(map[string]string)
    18  	for _, entry := range strings.Split(value, ",") {
    19  		k, v, _ := strings.Cut(entry, "=")
    20  		entriesMap[k] = v
    21  	}
    22  	expMap := make(map[string]string)
    23  	for _, exp := range strings.Split(expected, ",") {
    24  		k, v, _ := strings.Cut(exp, "=")
    25  		expMap[k] = v
    26  	}
    27  	assert.Check(t, is.DeepEqual(expMap, entriesMap))
    28  }