Repository: etcd-io/etcd
File: tests/robustness/coverage/sort_test.go (Go)

Code before:
			return strings.Compare(a.Pattern, b.Pattern)
		}
		if a.Method != b.Method {
			return strings.Compare(a.Method, b.Method)
		}
		return strings.Compare(a.Args, b.Args)
	})
	return keys
}

func TestSortPatternTable(t *testing.T) {
	want := []Row{
		{Method: "", Pattern: "/registry/events/", Args: ""},
		{Method: "List", Pattern: "/registry/events/{namespace}/", Args: ""},
		{Method: "Get", Pattern: "/registry/events/{namespace}/{name}", Args: ""},
		{Method: "Healthcheck", Pattern: "/registry/health", Args: ""},
		{Method: "List", Pattern: "/registry/masterleases/", Args: ""},
		{Method: "Get", Pattern: "/registry/masterleases/{name}", Args: ""},
		{Method: "List", Pattern: "/registry/{api-group}/{resource}/", Args: "XX"},
		{Method: "List", Pattern: "/registry/{api-group}/{resource}/", Args: "XXX"},
		{Method: "Get", Pattern: "/registry/{api-group}/{resource}/{name}", Args: ""},
		{Method: "Get", Pattern: "/registry/{resource}", Args: ""},
		{Method: "List", Pattern: "/registry/{resource}/", Args: ""},
		{Method: "Get", Pattern: "/registry/{resource}/{namespace}/{name}", Args: ""},
		{Method: "Get", Pattern: "/registry/{resource}/{name}", Args: ""},
		{Method: "Compaction", Pattern: "compact_rev_key", Args: ""},
	}
	res := make(map[Row]int, len(want))
	for _, r := range want {
		res[r] = 0
	}
	got := sortPatternTable(res)
	if diff := cmp.Diff(want, got); diff != "" {
		t.Logf("\n+%#v", got)
		t.Errorf("Sort mismatch (-want +got):\n%s", diff)
	}
}


Review comment (suggestion):
```suggestion
		{Pattern: "/registry/events/", Method: "", Args: ""},
		{Pattern: "/registry/events/{namespace}/", Method: "List", Args: ""},
		{Pattern: "/registry/events/{namespace}/{name}", Method: "Get", Args: ""},
		{Pattern: "/registry/health", Method: "Healthcheck", Args: ""},
		{Pattern: "/registry/masterleases/", Method: "List", Args: ""},
		{Pattern: "/registry/masterleases/{name}", Method: "Get", Args: ""},
		{Pattern: "/registry/{api-group}/{resource}/", Method: "List", Args: "XX"},
		{Pattern: "/registry/{api-group}/{resource}/", Method: "List", Args: "XXX"},
		{Pattern: "/registry/{api-group}/{resource}/{name}", Method: "Get", Args: ""},
		{Pattern: "/registry/{resource}", Method: "Get", Args: ""},
		{Pattern: "/registry/{resource}/", Method: "List", Args: ""},
		{Pattern: "/registry/{resource}/{namespace}/{name}", Method: "Get", Args: ""},
		{Pattern: "/registry/{resource}/{name}", Method: "Get", Args: ""},
		{Pattern: "compact_rev_key", Method: "Compaction", Args: ""},
```

Code after:
			return strings.Compare(a.Pattern, b.Pattern)
		}
		if a.Method != b.Method {
			return strings.Compare(a.Method, b.Method)
		}
		return strings.Compare(a.Args, b.Args)
	})
	return keys
}

func TestSortPatternTable(t *testing.T) {
	want := []Row{
		{Pattern: "/registry/events/", Method: "", Args: ""},
		{Pattern: "/registry/events/{namespace}/", Method: "List", Args: ""},
		{Pattern: "/registry/events/{namespace}/{name}", Method: "Get", Args: ""},
		{Pattern: "/registry/health", Method: "Healthcheck", Args: ""},
		{Pattern: "/registry/masterleases/", Method: "List", Args: ""},
		{Pattern: "/registry/masterleases/{name}", Method: "Get", Args: ""},
		{Pattern: "/registry/{api-group}/{resource}/", Method: "List", Args: "XX"},
		{Pattern: "/registry/{api-group}/{resource}/", Method: "List", Args: "XXX"},
		{Pattern: "/registry/{api-group}/{resource}/{name}", Method: "Get", Args: ""},
		{Pattern: "/registry/{resource}", Method: "Get", Args: ""},
		{Pattern: "/registry/{resource}/", Method: "List", Args: ""},
		{Pattern: "/registry/{resource}/{namespace}/{name}", Method: "Get", Args: ""},
		{Pattern: "/registry/{resource}/{name}", Method: "Get", Args: ""},
		{Pattern: "compact_rev_key", Method: "Compaction", Args: ""},
	}
	res := make(map[Row]int, len(want))
	for _, r := range want {
		res[r] = 0
	}
	got := sortPatternTable(res)
	if diff := cmp.Diff(want, got); diff != "" {
		t.Logf("\n+%#v", got)
		t.Errorf("Sort mismatch (-want +got):\n%s", diff)
	}
}