custom_test.go 830 B

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