notes-server/server/routes_test.go

61 lines
1.0 KiB
Go
Executable File

package server
import (
"net/http"
"net/http/httptest"
"net/url"
"testing"
)
func TestServerRoutes(t *testing.T) {
s := New()
err := s.Routes()
if err != nil {
t.Fatal(err)
}
}
func TestServerNotes(t *testing.T) {
s := New()
w := httptest.NewRecorder()
r := &http.Request{
URL: &url.URL{
Path: "/",
},
}
s.notes(w, r)
t.Logf("serve %s: %s", r.URL.Path, w.Body.Bytes())
w.Body.Reset()
r.URL.Path = "/notes/"
s.notes(w, r)
t.Logf("serve %s: %s", r.URL.Path, w.Body.Bytes())
w.Body.Reset()
r.URL.Path = "/notes/test"
s.notes(w, r)
t.Logf("serve %s: %s", r.URL.Path, w.Body.Bytes())
}
func TestServerNotesB(t *testing.T) {
s := New()
w := httptest.NewRecorder()
r := &http.Request{
URL: &url.URL{
Path: "/",
},
}
s.edit(w, r)
t.Logf("serve %s: %s", r.URL.Path, w.Body.Bytes())
w.Body.Reset()
r.URL.Path = "/edit/"
s.edit(w, r)
t.Logf("serve %s: %s", r.URL.Path, w.Body.Bytes())
w.Body.Reset()
r.URL.Path = "/edit/test"
s.edit(w, r)
t.Logf("serve %s: %s", r.URL.Path, w.Body.Bytes())
}