github.com/olljanat/moby@v1.13.1/cli/command/formatter/custom_test.go (about)

     1  package formatter
     2  
     3  import (
     4  	"reflect"
     5  	"strings"
     6  	"testing"
     7  )
     8  
     9  func compareMultipleValues(t *testing.T, value, expected string) {
    10  	// comma-separated values means probably a map input, which won't
    11  	// be guaranteed to have the same order as our expected value
    12  	// We'll create maps and use reflect.DeepEquals to check instead:
    13  	entriesMap := make(map[string]string)
    14  	expMap := make(map[string]string)
    15  	entries := strings.Split(value, ",")
    16  	expectedEntries := strings.Split(expected, ",")
    17  	for _, entry := range entries {
    18  		keyval := strings.Split(entry, "=")
    19  		entriesMap[keyval[0]] = keyval[1]
    20  	}
    21  	for _, expected := range expectedEntries {
    22  		keyval := strings.Split(expected, "=")
    23  		expMap[keyval[0]] = keyval[1]
    24  	}
    25  	if !reflect.DeepEqual(expMap, entriesMap) {
    26  		t.Fatalf("Expected entries: %v, got: %v", expected, value)
    27  	}
    28  }