func (s *EndpointSuite) TestEndpointSuite(c *C) {
	router := router.NewRouter(EndpointRoutes)
	server := httptest.NewServer(router)
	defer server.Close()

	dataProvider := []DataProvider{
		DataProvider{
			RequestedURL:       "/ping",
			RequestMethod:      "GET",
			RequestBody:        "",
			ExpectedBody:       "PONG",
			ExpectedReturnCode: http.StatusOK,
		},
		DataProvider{
			RequestedURL:       "/health",
			RequestMethod:      "GET",
			RequestBody:        "",
			ExpectedBody:       "OK",
			ExpectedReturnCode: http.StatusOK,
		},
	}

	for _, data := range dataProvider {
		req, err := http.NewRequest(
			data.RequestMethod,
			server.URL+data.RequestedURL,
			strings.NewReader(data.RequestBody),
		)
		c.Assert(err, IsNil)

		resp, err := http.DefaultClient.Do(req)
		c.Assert(err, IsNil)
		c.Assert(resp.StatusCode, Equals, data.ExpectedReturnCode)

		actual, err := ioutil.ReadAll(resp.Body)
		c.Assert(err, IsNil)

		obtained := strings.Trim(string(actual), "\n")
		c.Assert(obtained, Equals, data.ExpectedBody)
	}
}
Beispiel #2
0
func main() {
	router := router.NewRouter(endpoint.EndpointRoutes)

	fmt.Printf("Running...\n")
	log.Fatal(http.ListenAndServe(":8080", router))
}