shiori/internal/testutil/response.go
Felipe Martin 6f19c12c95
Start working on new REST API. Refactor logic in domains. (#497)
* added 404 template

* added auth domain

* added embed file for frontend

* added base config and dependencies

* added basic new http server

* added separated server command

* updated go modules

* removed modd file

* Added shortcut to send internal server error response

* Added JWT support to Auth Domain

* Added JWT support to API

* docs: added comments to response struct

* naming

* inline returns

* updated dependencies

* production logger

* bookmarks endpoint

* reverted old views api path

* frontend for api v1

* proper 404 error (not working atm)

* use response

* removed 404 html

* server error handler

* login and basic auth

* adjusted session duration

* properly retrieve tags

* properly delete bookmark

* cleanup

* archiver domain

* debug routes

* bookmark routes

* expiration by parameter

* move to logrus

* logout

* frontend cache

* updated dependencies

* http: migrated to gin

* linted

* Added version command

* unit tests, docs

* response test utils and tests

* remove logout handler

* auth

* createtag

* improved http test utilities

* assert message equals

* Remove 1.19 from test matrix

* moved api to v1 folder

* docs: contribute docs

* updated makefile

* updated usage docs

* warn in server command

* updaed docs with shiori version command

* Updated documentation

* deps: update
2023-07-17 14:30:18 +01:00

52 lines
1.2 KiB
Go

package testutil
import (
"encoding/json"
"io"
"testing"
"github.com/go-shiori/shiori/internal/http/response"
"github.com/pkg/errors"
"github.com/stretchr/testify/require"
)
type testResponse struct {
Response *response.Response
}
func (r *testResponse) AssertMessageIsEmptyList(t *testing.T) {
require.Equal(t, []interface{}{}, r.Response.Message)
}
func (r *testResponse) AssertNilMessage(t *testing.T) {
require.Equal(t, nil, r.Response.Message)
}
func (r testResponse) AssertMessageEquals(t *testing.T, expected interface{}) {
require.Equal(t, expected, r.Response.Message)
}
func (r *testResponse) AssertOk(t *testing.T) {
require.True(t, r.Response.Ok)
}
func (r *testResponse) AssertNotOk(t *testing.T) {
require.False(t, r.Response.Ok)
}
func NewTestResponseFromBytes(b []byte) (*testResponse, error) {
r := testResponse{}
if err := json.Unmarshal(b, &r.Response); err != nil {
return nil, errors.Wrap(err, "error parsing response")
}
return &r, nil
}
func NewTestResponseFromReader(r io.Reader) (*testResponse, error) {
response := testResponse{}
decoder := json.NewDecoder(r)
if err := decoder.Decode(&response.Response); err != nil {
return nil, errors.Wrap(err, "error parsing response")
}
return &response, nil
}