11 "golang.org/x/net/context"
13 "github.com/docker/docker/api/types/swarm"
16 func TestSwarmInitError(t *testing.T) {
18 client: newMockClient(errorMock(http.StatusInternalServerError, "Server error")),
21 _, err := client.SwarmInit(context.Background(), swarm.InitRequest{})
22 if err == nil || err.Error() != "Error response from daemon: Server error" {
23 t.Fatalf("expected a Server Error, got %v", err)
27 func TestSwarmInit(t *testing.T) {
28 expectedURL := "/swarm/init"
31 client: newMockClient(func(req *http.Request) (*http.Response, error) {
32 if !strings.HasPrefix(req.URL.Path, expectedURL) {
33 return nil, fmt.Errorf("Expected URL '%s', got '%s'", expectedURL, req.URL)
35 if req.Method != "POST" {
36 return nil, fmt.Errorf("expected POST method, got %s", req.Method)
38 return &http.Response{
39 StatusCode: http.StatusOK,
40 Body: ioutil.NopCloser(bytes.NewReader([]byte(`"body"`))),
45 resp, err := client.SwarmInit(context.Background(), swarm.InitRequest{
46 ListenAddr: "0.0.0.0:2377",
52 t.Fatalf("Expected 'body', got %s", resp)