fleet/server/handler_test.go
Zachary Wasserman 8f16bd8bcc Send configuration + label queries in distributed reads (#215)
This PR is the beginning of distributed query work. For now we are focusing on using the distributed query subsystem to retrieve the basic configuration information (currently just platform), and run the label queries.

A mockable clock interface is also added to the service struct, allowing us to inject a clock as a dependency, and write unit tests that can control the time.
2016-09-20 20:08:11 -07:00

128 lines
2.1 KiB
Go

package server
import (
"fmt"
"net/http/httptest"
"testing"
"github.com/gorilla/mux"
"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 := newTestService(ds)
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)
})
}
}