mirror of
https://github.com/empayre/fleet.git
synced 2024-11-07 01:15:22 +00:00
f46a951da3
* i like how I wrote this to never call svc direcly * rename func * apparently not everywhere * add service method for authenticated user * oops forgot to check this in
131 lines
2.3 KiB
Go
131 lines
2.3 KiB
Go
package server
|
|
|
|
import (
|
|
"fmt"
|
|
"net/http/httptest"
|
|
"testing"
|
|
|
|
kitlog "github.com/go-kit/kit/log"
|
|
"github.com/gorilla/mux"
|
|
"github.com/kolide/kolide-ose/config"
|
|
"github.com/kolide/kolide-ose/datastore"
|
|
"github.com/stretchr/testify/assert"
|
|
"golang.org/x/net/context"
|
|
)
|
|
|
|
func TestAPIRoutes(t *testing.T) {
|
|
ds, err := datastore.New("gorm-sqlite3", ":memory:")
|
|
assert.Nil(t, err)
|
|
|
|
svc, err := NewService(ds, kitlog.NewNopLogger(), config.TestConfig(), nil)
|
|
assert.Nil(t, err)
|
|
|
|
ctx := context.Background()
|
|
|
|
r := mux.NewRouter()
|
|
attachAPIRoutes(r, ctx, svc, nil)
|
|
handler := mux.NewRouter()
|
|
handler.PathPrefix("/api/v1/kolide").Handler(r)
|
|
|
|
var routes = []struct {
|
|
verb string
|
|
uri string
|
|
}{
|
|
{
|
|
verb: "POST",
|
|
uri: "/api/v1/kolide/users",
|
|
},
|
|
{
|
|
verb: "GET",
|
|
uri: "/api/v1/kolide/users",
|
|
},
|
|
{
|
|
verb: "GET",
|
|
uri: "/api/v1/kolide/users/1",
|
|
},
|
|
{
|
|
verb: "PATCH",
|
|
uri: "/api/v1/kolide/users/1",
|
|
},
|
|
{
|
|
verb: "POST",
|
|
uri: "/api/v1/kolide/login",
|
|
},
|
|
{
|
|
verb: "POST",
|
|
uri: "/api/v1/kolide/forgot_password",
|
|
},
|
|
{
|
|
verb: "POST",
|
|
uri: "/api/v1/kolide/reset_password",
|
|
},
|
|
{
|
|
verb: "GET",
|
|
uri: "/api/v1/kolide/me",
|
|
},
|
|
{
|
|
verb: "GET",
|
|
uri: "/api/v1/kolide/queries/1",
|
|
},
|
|
{
|
|
verb: "GET",
|
|
uri: "/api/v1/kolide/queries",
|
|
},
|
|
{
|
|
verb: "POST",
|
|
uri: "/api/v1/kolide/queries",
|
|
},
|
|
{
|
|
verb: "PATCH",
|
|
uri: "/api/v1/kolide/queries/1",
|
|
},
|
|
{
|
|
verb: "DELETE",
|
|
uri: "/api/v1/kolide/queries/1",
|
|
},
|
|
{
|
|
verb: "GET",
|
|
uri: "/api/v1/kolide/packs/1",
|
|
},
|
|
{
|
|
verb: "GET",
|
|
uri: "/api/v1/kolide/packs",
|
|
},
|
|
{
|
|
verb: "POST",
|
|
uri: "/api/v1/kolide/packs",
|
|
},
|
|
{
|
|
verb: "PATCH",
|
|
uri: "/api/v1/kolide/packs/1",
|
|
},
|
|
{
|
|
verb: "DELETE",
|
|
uri: "/api/v1/kolide/packs/1",
|
|
},
|
|
{
|
|
verb: "GET",
|
|
uri: "/api/v1/kolide/packs/1/queries/2",
|
|
},
|
|
{
|
|
verb: "GET",
|
|
uri: "/api/v1/kolide/packs/1/queries",
|
|
},
|
|
{
|
|
verb: "DELETE",
|
|
uri: "/api/v1/kolide/packs/1/queries/2",
|
|
},
|
|
}
|
|
|
|
for _, route := range routes {
|
|
t.Run(fmt.Sprintf(": %v", route.uri), func(st *testing.T) {
|
|
recorder := httptest.NewRecorder()
|
|
handler.ServeHTTP(
|
|
recorder,
|
|
httptest.NewRequest(route.verb, route.uri, nil),
|
|
)
|
|
assert.NotEqual(st, 404, recorder.Code)
|
|
})
|
|
}
|
|
}
|