github.com/ali-iotechsys/cli@v20.10.0+incompatible/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  	// comma-separated values means probably a map input, which won't
    14  	// be guaranteed to have the same order as our expected value
    15  	// We'll create maps and use reflect.DeepEquals to check instead:
    16  	entriesMap := make(map[string]string)
    17  	expMap := make(map[string]string)
    18  	entries := strings.Split(value, ",")
    19  	expectedEntries := strings.Split(expected, ",")
    20  	for _, entry := range entries {
    21  		keyval := strings.Split(entry, "=")
    22  		entriesMap[keyval[0]] = keyval[1]
    23  	}
    24  	for _, expected := range expectedEntries {
    25  		keyval := strings.Split(expected, "=")
    26  		expMap[keyval[0]] = keyval[1]
    27  	}
    28  	assert.Check(t, is.DeepEqual(expMap, entriesMap))
    29  }