fleet/server/service/transport_targets_test.go
Zachary Wasserman 715d908613 Update go-kit to 0.4.0 (#1411)
Notable refactoring:
- Use stdlib "context" in place of "golang.org/x/net/context"
- Go-kit no longer wraps errors, so we remove the unwrap in transport_error.go
- Use MakeHandler when setting up endpoint tests (fixes test bug caught during
  this refactoring)

Closes #1411.
2017-03-15 08:55:30 -07:00

47 lines
900 B
Go

package service
import (
"bytes"
"context"
"net/http"
"net/http/httptest"
"testing"
"github.com/gorilla/mux"
"github.com/stretchr/testify/assert"
)
func TestDecodeSearchTargetsRequest(t *testing.T) {
router := mux.NewRouter()
router.HandleFunc("/api/v1/kolide/targets", func(writer http.ResponseWriter, request *http.Request) {
r, err := decodeSearchTargetsRequest(context.Background(), request)
assert.Nil(t, err)
params := r.(searchTargetsRequest)
assert.Equal(t, "bar", params.Query)
assert.Len(t, params.Selected.Hosts, 3)
assert.Len(t, params.Selected.Labels, 2)
}).Methods("POST")
var body bytes.Buffer
body.Write([]byte(`{
"query": "bar",
"selected": {
"hosts": [
1,
2,
3
],
"labels": [
1,
2
]
}
}`))
router.ServeHTTP(
httptest.NewRecorder(),
httptest.NewRequest("POST", "/api/v1/kolide/targets", &body),
)
}