forked from docker-archive/classicswarm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapi_test.go
43 lines (35 loc) · 884 Bytes
/
api_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
package api
import (
"encoding/json"
"net/http"
"net/http/httptest"
"testing"
"github.com/docker/swarm/cluster"
"github.com/docker/swarm/scheduler"
"github.com/stretchr/testify/assert"
)
func serveRequest(c *cluster.Cluster, s *scheduler.Scheduler, w http.ResponseWriter, req *http.Request) error {
context := &context{
cluster: c,
scheduler: s,
version: "test-version",
}
r, err := createRouter(context, false)
if err != nil {
return err
}
r.ServeHTTP(w, req)
return nil
}
func TestGetVersion(t *testing.T) {
r := httptest.NewRecorder()
req, err := http.NewRequest("GET", "/version", nil)
assert.NoError(t, err)
assert.NoError(t, serveRequest(nil, nil, r, req))
assert.Equal(t, r.Code, http.StatusOK)
version := struct {
Version string
}{}
json.NewDecoder(r.Body).Decode(&version)
assert.Equal(t, version.Version, "swarm/test-version")
}