forked from barak/tarpoon
Add glide.yaml and vendor deps
This commit is contained in:
parent
db918f12ad
commit
5b3d5e81bd
18880 changed files with 5166045 additions and 1 deletions
91
vendor/github.com/docker/engine-api/client/request_test.go
generated
vendored
Normal file
91
vendor/github.com/docker/engine-api/client/request_test.go
generated
vendored
Normal file
|
|
@ -0,0 +1,91 @@
|
|||
package client
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/docker/engine-api/types"
|
||||
"golang.org/x/net/context"
|
||||
)
|
||||
|
||||
// TestSetHostHeader should set fake host for local communications, set real host
|
||||
// for normal communications.
|
||||
func TestSetHostHeader(t *testing.T) {
|
||||
testURL := "/test"
|
||||
testCases := []struct {
|
||||
host string
|
||||
expectedHost string
|
||||
expectedURLHost string
|
||||
}{
|
||||
{
|
||||
"unix:///var/run/docker.sock",
|
||||
"docker",
|
||||
"/var/run/docker.sock",
|
||||
},
|
||||
{
|
||||
"npipe:////./pipe/docker_engine",
|
||||
"docker",
|
||||
"//./pipe/docker_engine",
|
||||
},
|
||||
{
|
||||
"tcp://0.0.0.0:4243",
|
||||
"",
|
||||
"0.0.0.0:4243",
|
||||
},
|
||||
{
|
||||
"tcp://localhost:4243",
|
||||
"",
|
||||
"localhost:4243",
|
||||
},
|
||||
}
|
||||
|
||||
for c, test := range testCases {
|
||||
proto, addr, basePath, err := ParseHost(test.host)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
client := &Client{
|
||||
transport: newMockClient(nil, func(req *http.Request) (*http.Response, error) {
|
||||
if !strings.HasPrefix(req.URL.Path, testURL) {
|
||||
return nil, fmt.Errorf("Test Case #%d: Expected URL %q, got %q", c, testURL, req.URL)
|
||||
}
|
||||
if req.Host != test.expectedHost {
|
||||
return nil, fmt.Errorf("Test Case #%d: Expected host %q, got %q", c, test.expectedHost, req.Host)
|
||||
}
|
||||
if req.URL.Host != test.expectedURLHost {
|
||||
return nil, fmt.Errorf("Test Case #%d: Expected URL host %q, got %q", c, test.expectedURLHost, req.URL.Host)
|
||||
}
|
||||
return &http.Response{
|
||||
StatusCode: http.StatusOK,
|
||||
Body: ioutil.NopCloser(bytes.NewReader(([]byte("")))),
|
||||
}, nil
|
||||
}),
|
||||
proto: proto,
|
||||
addr: addr,
|
||||
basePath: basePath,
|
||||
}
|
||||
|
||||
_, err = client.sendRequest(context.Background(), "GET", testURL, nil, nil, nil)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// TestPlainTextError tests the server returning an error in plain text for
|
||||
// backwards compatibility with API versions <1.24. All other tests use
|
||||
// errors returned as JSON
|
||||
func TestPlainTextError(t *testing.T) {
|
||||
client := &Client{
|
||||
transport: newMockClient(nil, plainTextErrorMock(http.StatusInternalServerError, "Server error")),
|
||||
}
|
||||
_, err := client.ContainerList(context.Background(), types.ContainerListOptions{})
|
||||
if err == nil || err.Error() != "Error response from daemon: Server error" {
|
||||
t.Fatalf("expected a Server Error, got %v", err)
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue