Beispiel #1
0
func checkCorrectness(
	t *testing.T, data map[uint32]map[uint32]uint32, h *cart.Handler) {

	for customer, _ := range data {
		r := listRequest(t, "customer", customer)
		w := httptest.NewRecorder()
		h.List(w, r)
		lines := strings.Split(w.Body.String(), "\n")
		for i := 1; i < len(lines); i++ {
			p := strings.Split(lines[i], " ")
			if len(p) < 2 {
				continue
			}
			i, err := strconv.Atoi(p[0])
			if err != nil {
				t.Fatalf("unexpected error: %s", err)
			}

			n, err := strconv.Atoi(p[1])
			if err != nil {
				t.Fatalf("unexpected error: %s", err)
			}

			if data[customer][uint32(i)] != uint32(n) {
				t.Fatalf("customer %v has %v of %v instead of %v",
					customer, n)
			}
		}
	}
}