whee
This commit is contained in:
60
spike/review/reinvent/ezmded/server/server_test.go
Normal file
60
spike/review/reinvent/ezmded/server/server_test.go
Normal file
@@ -0,0 +1,60 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestServerRoutes(t *testing.T) {
|
||||
server := NewServer(t.TempDir())
|
||||
if err := server.Routes(); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
cases := map[string]struct {
|
||||
path string
|
||||
method string
|
||||
}{
|
||||
"v0: /: get": {
|
||||
path: "/",
|
||||
method: http.MethodGet,
|
||||
},
|
||||
"v0: search: get": {
|
||||
path: "/api/v0/search",
|
||||
method: http.MethodGet,
|
||||
},
|
||||
"v0: tree: get": {
|
||||
path: "/api/v0/tree",
|
||||
method: http.MethodGet,
|
||||
},
|
||||
"v0: media: post": {
|
||||
path: "/api/v0/media",
|
||||
method: http.MethodPost,
|
||||
},
|
||||
"v0: media id: get": {
|
||||
path: "/api/v0/media/id",
|
||||
method: http.MethodGet,
|
||||
},
|
||||
"v0: files: post": {
|
||||
path: "/api/v0/files",
|
||||
method: http.MethodPost,
|
||||
},
|
||||
"v0: files id: get": {
|
||||
path: "/api/v0/files/id",
|
||||
method: http.MethodGet,
|
||||
},
|
||||
}
|
||||
|
||||
for name, d := range cases {
|
||||
c := d
|
||||
t.Run(name, func(t *testing.T) {
|
||||
r := httptest.NewRequest(c.method, c.path, nil)
|
||||
w := httptest.NewRecorder()
|
||||
server.ServeHTTP(w, r)
|
||||
if w.Code == http.StatusNotFound {
|
||||
t.Fatal(w)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user