fixing style
This commit is contained in:
parent
e454940dfa
commit
f40485842d
35 changed files with 16000 additions and 286 deletions
|
|
@ -32,6 +32,15 @@ func (f *fakeContent) Update(_ context.Context, c service.Content) (service.Cont
|
|||
f.updated = true
|
||||
return c, nil
|
||||
}
|
||||
func (f *fakeContent) Create(_ context.Context, c service.Content) (service.Content, error) {
|
||||
return c, nil
|
||||
}
|
||||
func (f *fakeContent) Delete(_ context.Context, _ string) error {
|
||||
return nil
|
||||
}
|
||||
func (f *fakeContent) Reset(_ context.Context) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func newTestRoutes(content *fakeContent, browser ...*golooseauth.Auth) http.Handler {
|
||||
assets := fstest.MapFS{
|
||||
|
|
@ -171,4 +180,48 @@ func TestServesEmbeddedAppForClientRoutes(t *testing.T) {
|
|||
if page.Code != http.StatusOK || !strings.Contains(page.Body.String(), `id="root"`) {
|
||||
t.Fatalf("spa fallback status = %d body = %q", page.Code, page.Body.String())
|
||||
}
|
||||
|
||||
devNull := httptest.NewRecorder()
|
||||
routes.ServeHTTP(devNull, httptest.NewRequest(http.MethodGet, "/dev/null", nil))
|
||||
if devNull.Code != http.StatusOK || !strings.Contains(devNull.Body.String(), `id="root"`) {
|
||||
t.Fatalf("dev/null fallback status = %d body = %q", devNull.Code, devNull.Body.String())
|
||||
}
|
||||
|
||||
backlogRc := httptest.NewRecorder()
|
||||
routes.ServeHTTP(backlogRc, httptest.NewRequest(http.MethodGet, "/etc/backlog.rc", nil))
|
||||
if backlogRc.Code != http.StatusOK || !strings.Contains(backlogRc.Body.String(), `id="root"`) {
|
||||
t.Fatalf("backlog.rc fallback status = %d body = %q", backlogRc.Code, backlogRc.Body.String())
|
||||
}
|
||||
}
|
||||
|
||||
func TestContentCRUDAndClear(t *testing.T) {
|
||||
content := &fakeContent{}
|
||||
routes := newTestRoutes(content)
|
||||
|
||||
// Create with SSO header
|
||||
postReq := httptest.NewRequest(http.MethodPost, "/api/content", strings.NewReader(`{"title":"New Post","body":"Content body"}`))
|
||||
postReq.Header.Set("X-SSO-Token", "valid")
|
||||
postRec := httptest.NewRecorder()
|
||||
routes.ServeHTTP(postRec, postReq)
|
||||
if postRec.Code != http.StatusCreated {
|
||||
t.Fatalf("create status = %d, want %d", postRec.Code, http.StatusCreated)
|
||||
}
|
||||
|
||||
// Delete with SSO header
|
||||
delReq := httptest.NewRequest(http.MethodDelete, "/api/content/post", nil)
|
||||
delReq.Header.Set("X-SSO-Token", "valid")
|
||||
delRec := httptest.NewRecorder()
|
||||
routes.ServeHTTP(delRec, delReq)
|
||||
if delRec.Code != http.StatusNoContent {
|
||||
t.Fatalf("delete status = %d, want %d", delRec.Code, http.StatusNoContent)
|
||||
}
|
||||
|
||||
// Reset with SSO header
|
||||
resetReq := httptest.NewRequest(http.MethodPost, "/api/admin/reset", nil)
|
||||
resetReq.Header.Set("X-SSO-Token", "valid")
|
||||
resetRec := httptest.NewRecorder()
|
||||
routes.ServeHTTP(resetRec, resetReq)
|
||||
if resetRec.Code != http.StatusOK {
|
||||
t.Fatalf("reset status = %d, want %d", resetRec.Code, http.StatusOK)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue