1
0
Fork 0
mirror of https://github.com/moby/moby.git synced 2022-11-09 12:21:53 -05:00

client: remove transport package

This package doesn't really seem to do anything of real interest.
Removing it and replacing with a few helper functions. Most of this was
maintaining a fork of ctxhttp to support a mock that was unnecessary.

We could probably do with a further refactor of the client interface.
There is a lot of confusion of between transport, http layer and
application layer that makes for some awkward code. This change
improves the situation to the point where no breaking changes are
introduced.

Signed-off-by: Stephen J Day <stephen.day@docker.com>
This commit is contained in:
Stephen J Day 2016-09-08 20:44:25 -07:00
parent 9d7be9df8f
commit 9a072adff3
No known key found for this signature in database
GPG key ID: FB5F6B2905D7ECF3
86 changed files with 276 additions and 533 deletions

View file

@ -18,7 +18,7 @@ import (
func TestImageSearchAnyError(t *testing.T) {
client := &Client{
transport: newMockClient(nil, errorMock(http.StatusInternalServerError, "Server error")),
client: newMockClient(errorMock(http.StatusInternalServerError, "Server error")),
}
_, err := client.ImageSearch(context.Background(), "some-image", types.ImageSearchOptions{})
if err == nil || err.Error() != "Error response from daemon: Server error" {
@ -28,7 +28,7 @@ func TestImageSearchAnyError(t *testing.T) {
func TestImageSearchStatusUnauthorizedError(t *testing.T) {
client := &Client{
transport: newMockClient(nil, errorMock(http.StatusUnauthorized, "Unauthorized error")),
client: newMockClient(errorMock(http.StatusUnauthorized, "Unauthorized error")),
}
_, err := client.ImageSearch(context.Background(), "some-image", types.ImageSearchOptions{})
if err == nil || err.Error() != "Error response from daemon: Unauthorized error" {
@ -38,7 +38,7 @@ func TestImageSearchStatusUnauthorizedError(t *testing.T) {
func TestImageSearchWithUnauthorizedErrorAndPrivilegeFuncError(t *testing.T) {
client := &Client{
transport: newMockClient(nil, errorMock(http.StatusUnauthorized, "Unauthorized error")),
client: newMockClient(errorMock(http.StatusUnauthorized, "Unauthorized error")),
}
privilegeFunc := func() (string, error) {
return "", fmt.Errorf("Error requesting privilege")
@ -53,7 +53,7 @@ func TestImageSearchWithUnauthorizedErrorAndPrivilegeFuncError(t *testing.T) {
func TestImageSearchWithUnauthorizedErrorAndAnotherUnauthorizedError(t *testing.T) {
client := &Client{
transport: newMockClient(nil, errorMock(http.StatusUnauthorized, "Unauthorized error")),
client: newMockClient(errorMock(http.StatusUnauthorized, "Unauthorized error")),
}
privilegeFunc := func() (string, error) {
return "a-auth-header", nil
@ -69,7 +69,7 @@ func TestImageSearchWithUnauthorizedErrorAndAnotherUnauthorizedError(t *testing.
func TestImageSearchWithPrivilegedFuncNoError(t *testing.T) {
expectedURL := "/images/search"
client := &Client{
transport: newMockClient(nil, func(req *http.Request) (*http.Response, error) {
client: newMockClient(func(req *http.Request) (*http.Response, error) {
if !strings.HasPrefix(req.URL.Path, expectedURL) {
return nil, fmt.Errorf("Expected URL '%s', got '%s'", expectedURL, req.URL)
}
@ -126,7 +126,7 @@ func TestImageSearchWithoutErrors(t *testing.T) {
expectedFilters := `{"is-automated":{"true":true},"stars":{"3":true}}`
client := &Client{
transport: newMockClient(nil, func(req *http.Request) (*http.Response, error) {
client: newMockClient(func(req *http.Request) (*http.Response, error) {
if !strings.HasPrefix(req.URL.Path, expectedURL) {
return nil, fmt.Errorf("Expected URL '%s', got '%s'", expectedURL, req.URL)
}