// Create a customer for a // given shop. func AddAccount(w http.ResponseWriter, req *http.Request, params martini.Params, enc encoding.Encoder, shop *cart.Shop) string { var c cart.Customer defer req.Body.Close() data, err := ioutil.ReadAll(req.Body) if err != nil { apierror.GenerateError(err.Error(), err, w, req) return "" } if err = json.Unmarshal(data, &c); err != nil { apierror.GenerateError(err.Error(), err, w, req) return "" } c.ShopId = shop.Id if err = c.Insert(req.Referer()); err != nil { apierror.GenerateError(err.Error(), err, w, req) return "" } return encoding.Must(enc.Encode(c)) }
func BenchmarkGetCustomerAddresses(b *testing.B) { shopID := cart.InsertTestData() if shopID == nil { b.Error("failed to create a shop") b.Fail() } val := shopID.Hex() qs := make(url.Values, 0) qs.Add("shop", val) cust := cart.Customer{ ShopId: *shopID, FirstName: "Alex", LastName: "Ninneman", Email: time.Now().Format(time.RFC3339Nano) + "@gmail.com", Password: "******", } if err := cust.Insert("http://www.example.com"); err != nil { b.Error(err.Error()) b.Fail() } (&httprunner.BenchmarkOptions{ Method: "GET", Route: "/shopify/customers/" + cust.Id.Hex() + "/addresses", ParameterizedRoute: "/shopify/customers/:id/addresses", Handler: GetAddresses, QueryString: &qs, Runs: b.N, }).RequestBenchmark() }