func TestHasRoleReturnFalse(t *testing.T) {
	handler := booking_handler_mock.New()
	r := New(createVerifyLogin(false, nil), createHasRole(false, nil), createHttpRequestToAuthentication(nil, nil), booking_authorization.Administrator, handler)
	if err := AssertThat(r.ServeHTTP(server_mock.NewHttpResponseWriterMock(), &http.Request{}), NotNilValue()); err != nil {
		t.Fatal(err)
	}
	if err := AssertThat(handler.Request == nil, Is(true)); err != nil {
		t.Fatal(err)
	}
	if err := AssertThat(handler.Response == nil, Is(true)); err != nil {
		t.Fatal(err)
	}
}
func TestHasRoleFailed(t *testing.T) {
	e := fmt.Errorf("myError")
	handler := booking_handler_mock.New()
	r := New(createVerifyLogin(true, nil), createHasRole(true, e), createHttpRequestToAuthentication(nil, nil), booking_authorization.Administrator, handler)
	if err := AssertThat(r.ServeHTTP(server_mock.NewHttpResponseWriterMock(), &http.Request{}), Is(e)); err != nil {
		t.Fatal(err)
	}
	if err := AssertThat(handler.Request == nil, Is(true)); err != nil {
		t.Fatal(err)
	}
	if err := AssertThat(handler.Response == nil, Is(true)); err != nil {
		t.Fatal(err)
	}
}
예제 #3
0
func TestDate(t *testing.T) {
	resp := server_mock.NewHttpResponseWriterMock()
	db := booking_database_sqlite.New("/tmp/booking_test.db", false)
	userService := booking_user_service.New(booking_user_storage.New(db))
	handler := createHandler(db, userService)
	req, err := createRequest("/date", userService)
	if err = AssertThat(err, NilValue()); err != nil {
		t.Fatal(err)
	}
	handler.ServeHTTP(resp, req)
	if err = AssertThat(resp.Status(), Is(200)); err != nil {
		t.Fatal(err)
	}
}
예제 #4
0
func TestVerifyLoginHandlerFound(t *testing.T) {
	resp := server_mock.NewHttpResponseWriterMock()
	db := booking_database_sqlite.New("/tmp/booking_test.db", false)
	userService := booking_user_service.New(booking_user_storage.New(db))
	_, err := userService.Create(&booking_user.User{Login: "******", Password: "******"})
	if err = AssertThat(err, NilValue()); err != nil {
		t.Fatal(err)
	}
	handler := createHandler(db, userService)
	req, err := createRequest("/authentication/verifyLogin", userService)
	if err = AssertThat(err, NilValue()); err != nil {
		t.Fatal(err)
	}
	req.Body = io_mock.NewReadCloserString(`{"login":"******","password":"******"}`)
	req.Method = "POST"
	handler.ServeHTTP(resp, req)
	if err = AssertThat(resp.Status(), Is(200)); err != nil {
		t.Fatal(err)
	}
}