mirror of
https://github.com/empayre/fleet.git
synced 2024-11-07 01:15:22 +00:00
a8a7be7f20
* initial scaffolding * pack info sidebar * fixing the merge of the routes * Remove radium from pack info sidepanel * lint * cards! * redux entity config * pack interface * wiring up redux with fake dev data * Add description attribute to packs * move redux to top level page component to isolate data fetching * initial scaffolding of all packs table * adding redux entities back * minimal * alpha order in packs.js * no newlines in HTML * onclick handler to function on component class * alpha order in router * alpha order in paths.js * no newline in side panel * removing input field * lint fixes
142 lines
4.0 KiB
Go
142 lines
4.0 KiB
Go
package service
|
|
|
|
import (
|
|
"bytes"
|
|
"net/http"
|
|
"net/http/httptest"
|
|
"testing"
|
|
|
|
"github.com/gorilla/mux"
|
|
"github.com/stretchr/testify/assert"
|
|
"golang.org/x/net/context"
|
|
)
|
|
|
|
func TestDecodeCreatePackRequest(t *testing.T) {
|
|
router := mux.NewRouter()
|
|
router.HandleFunc("/api/v1/kolide/packs", func(writer http.ResponseWriter, request *http.Request) {
|
|
r, err := decodeCreatePackRequest(context.Background(), request)
|
|
assert.Nil(t, err)
|
|
|
|
params := r.(createPackRequest)
|
|
assert.Equal(t, "foo", *params.payload.Name)
|
|
assert.Equal(t, "bar", *params.payload.Description)
|
|
}).Methods("POST")
|
|
|
|
var body bytes.Buffer
|
|
body.Write([]byte(`{
|
|
"name": "foo",
|
|
"description": "bar"
|
|
}`))
|
|
|
|
router.ServeHTTP(
|
|
httptest.NewRecorder(),
|
|
httptest.NewRequest("POST", "/api/v1/kolide/packs", &body),
|
|
)
|
|
}
|
|
|
|
func TestDecodeModifyPackRequest(t *testing.T) {
|
|
router := mux.NewRouter()
|
|
router.HandleFunc("/api/v1/kolide/packs/{id}", func(writer http.ResponseWriter, request *http.Request) {
|
|
r, err := decodeModifyPackRequest(context.Background(), request)
|
|
assert.Nil(t, err)
|
|
|
|
params := r.(modifyPackRequest)
|
|
assert.Equal(t, "foo", *params.payload.Name)
|
|
assert.Equal(t, "bar", *params.payload.Description)
|
|
assert.Equal(t, uint(1), params.ID)
|
|
}).Methods("PATCH")
|
|
|
|
var body bytes.Buffer
|
|
body.Write([]byte(`{
|
|
"name": "foo",
|
|
"description": "bar"
|
|
}`))
|
|
|
|
router.ServeHTTP(
|
|
httptest.NewRecorder(),
|
|
httptest.NewRequest("PATCH", "/api/v1/kolide/packs/1", &body),
|
|
)
|
|
}
|
|
|
|
func TestDecodeDeletePackRequest(t *testing.T) {
|
|
router := mux.NewRouter()
|
|
router.HandleFunc("/api/v1/kolide/packs/{id}", func(writer http.ResponseWriter, request *http.Request) {
|
|
r, err := decodeDeletePackRequest(context.Background(), request)
|
|
assert.Nil(t, err)
|
|
|
|
params := r.(deletePackRequest)
|
|
assert.Equal(t, uint(1), params.ID)
|
|
}).Methods("DELETE")
|
|
|
|
router.ServeHTTP(
|
|
httptest.NewRecorder(),
|
|
httptest.NewRequest("DELETE", "/api/v1/kolide/packs/1", nil),
|
|
)
|
|
}
|
|
|
|
func TestDecodeGetPackRequest(t *testing.T) {
|
|
router := mux.NewRouter()
|
|
router.HandleFunc("/api/v1/kolide/packs/{id}", func(writer http.ResponseWriter, request *http.Request) {
|
|
r, err := decodeGetPackRequest(context.Background(), request)
|
|
assert.Nil(t, err)
|
|
|
|
params := r.(getPackRequest)
|
|
assert.Equal(t, uint(1), params.ID)
|
|
}).Methods("GET")
|
|
|
|
router.ServeHTTP(
|
|
httptest.NewRecorder(),
|
|
httptest.NewRequest("GET", "/api/v1/kolide/packs/1", nil),
|
|
)
|
|
}
|
|
|
|
func TestDecodeAddQueryToPackRequest(t *testing.T) {
|
|
router := mux.NewRouter()
|
|
router.HandleFunc("/api/v1/kolide/packs/{pid}/queries/{qid}", func(writer http.ResponseWriter, request *http.Request) {
|
|
r, err := decodeAddQueryToPackRequest(context.Background(), request)
|
|
assert.Nil(t, err)
|
|
|
|
params := r.(addQueryToPackRequest)
|
|
assert.Equal(t, uint(1), params.PackID)
|
|
assert.Equal(t, uint(2), params.QueryID)
|
|
}).Methods("GET")
|
|
|
|
router.ServeHTTP(
|
|
httptest.NewRecorder(),
|
|
httptest.NewRequest("GET", "/api/v1/kolide/packs/1/queries/2", nil),
|
|
)
|
|
}
|
|
|
|
func TestDecodeGetQueriesInPackRequest(t *testing.T) {
|
|
router := mux.NewRouter()
|
|
router.HandleFunc("/api/v1/kolide/packs/{id}/queries", func(writer http.ResponseWriter, request *http.Request) {
|
|
r, err := decodeGetQueriesInPackRequest(context.Background(), request)
|
|
assert.Nil(t, err)
|
|
|
|
params := r.(getQueriesInPackRequest)
|
|
assert.Equal(t, uint(1), params.ID)
|
|
}).Methods("GET")
|
|
|
|
router.ServeHTTP(
|
|
httptest.NewRecorder(),
|
|
httptest.NewRequest("GET", "/api/v1/kolide/packs/1/queries", nil),
|
|
)
|
|
}
|
|
|
|
func TestDecodeDeleteQueryFromPackRequest(t *testing.T) {
|
|
router := mux.NewRouter()
|
|
router.HandleFunc("/api/v1/kolide/packs/{pid}/queries/{qid}", func(writer http.ResponseWriter, request *http.Request) {
|
|
r, err := decodeDeleteQueryFromPackRequest(context.Background(), request)
|
|
assert.Nil(t, err)
|
|
|
|
params := r.(deleteQueryFromPackRequest)
|
|
assert.Equal(t, uint(1), params.PackID)
|
|
assert.Equal(t, uint(2), params.QueryID)
|
|
}).Methods("DELETE")
|
|
|
|
router.ServeHTTP(
|
|
httptest.NewRecorder(),
|
|
httptest.NewRequest("DELETE", "/api/v1/kolide/packs/1/queries/2", nil),
|
|
)
|
|
}
|