// FIXME XXX: test non valid request, like without orderId and so on func TestAliasDirectLinkEndpoint(t *testing.T) { metric := &metric.Metric{} config := ogone.NewConfig( "ewgraogone", "ewgragolang", "123123aa", "qwdqwoidj29812d9", true, ) ep := &Endpoint{M: metric, C: config} ks := NewKitHandler(context.Background(), ep) server := httptest.NewServer(ks) defer server.Close() orderID := "GOLANGTEST" + time.Now().Format("20060102150405_") + strconv.Itoa(rand.Intn(100000)) aResp := ogonelib.NewTestAliasResponse(orderID, t) jsonRequest, _ := json.Marshal(map[string]string{"orderId": orderID, "alias": aResp.Alias(), "amount": "105"}) resp, _ := http.Post(server.URL, "application/json", strings.NewReader(string(jsonRequest))) buf, _ := ioutil.ReadAll(resp.Body) if string(buf) != "{\"v\":\"OK\"}\n" { fmt.Println(string(buf)) t.Fatalf("Wrong alias direct link response") } if metric.GetRequestsCount() != 1 { t.Fatalf("Wrong metric for requests count") } }
// Run the alias direct link service func Run() { conf := service.NewConfig("", 8080, "/alias_direct_link.json", "/alias_direct_link.metric.json") // FIXME XXX: must be configured endpointConf := ogone.NewConfig( "ewgraogone", "ewgragolang", "123123aa", "qwdqwoidj29812d9", true, ) m := &metric.Metric{} ep := &Endpoint{M: m, C: endpointConf} ks := NewKitHandler(context.Background(), ep) http.Handle(conf.GetPath(), ks) metricEp := &metric.Endpoint{M: m} metricKs := metric.NewKitHandler(context.Background(), metricEp) http.Handle(conf.GetMetricPath(), metricKs) log.Fatal(http.ListenAndServe(conf.GetHost()+":"+fmt.Sprint(conf.GetPort()), nil)) }