Beispiel #1
0
func main() {
	l := logger.New()

	txManager, err := newTxManager()
	if err != nil {
		log.Fatal(errors.ErrorWithStack(err))
	}

	router := web.NewRouter(l, txManager)

	port := getPort()
	l.Printf("Starting server on port=%s", port)

	err = http.ListenAndServe(port, router)
	if err != nil {
		log.Fatalf("Can not start server\n%s", errors.ErrorWithStack(err))
	}
}
Beispiel #2
0
func TestAPIExpenses(t *testing.T) {
	txManager := dbtest.NewTxManager()
	defer txManager.Rollback()

	router := web.NewRouter(logger.Discard, txManager)
	s := testclient.New(router)

	{
		status, body, err := s.PostForm("/api/v1/expenses", "description=asd&amount=12")
		assert.MustBeNil(t, err)
		defer body.Close()

		assert.Equal(t, 201, status)
		AssertJSONSchema(t,
			schema.Map{
				"amount":      12,
				"description": "asd",
			},
			body,
		)
	}

	{
		status, body, err := s.Get("/api/v1/expenses")
		assert.MustBeNil(t, err)
		defer body.Close()

		assert.Equal(t, 200, status)
		AssertJSONSchema(t,
			schema.Array(
				schema.Map{
					"amount":      12,
					"description": "asd",
				}),
			body,
		)
	}
}