mirror of
https://github.com/empayre/fleet.git
synced 2024-11-06 17:05:18 +00:00
8ee47f8b23
- Accept Teams as a searchable target type for the target selection API. - Accept Teams for targets in running live queries. - Refactoring to support these changes. - Update API documentation.
47 lines
907 B
Go
47 lines
907 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/fleet/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.MatchQuery)
|
|
assert.Len(t, params.Selected.HostIDs, 3)
|
|
assert.Len(t, params.Selected.LabelIDs, 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/fleet/targets", &body),
|
|
)
|
|
}
|