From 46ba8763bef774555c12990336ddf0ca97fec69d Mon Sep 17 00:00:00 2001 From: Nishant Totla Date: Wed, 25 May 2016 16:03:57 -0700 Subject: [PATCH] Updating unit tests for updated engine-api Signed-off-by: Nishant Totla --- cluster/engine.go | 9 ++++++--- cluster/engine_test.go | 6 +++--- cluster/swarm/cluster_test.go | 6 +++--- 3 files changed, 12 insertions(+), 9 deletions(-) diff --git a/cluster/engine.go b/cluster/engine.go index 2b5adb497f..9b8c4d69b3 100644 --- a/cluster/engine.go +++ b/cluster/engine.go @@ -959,10 +959,14 @@ func (e *Engine) CreateVolume(request *types.VolumeCreateRequest) (*Volume, erro // Pull an image on the engine func (e *Engine) Pull(image string, authConfig *types.AuthConfig) error { - // TODO(nishanttotla): RegistryAuth probably needs fixing + // TODO(nishanttotla): RegistryAuth needs fixing + registryAuth := "" + if authConfig != nil { + registryAuth = authConfig.Auth + } pullOpts := types.ImagePullOptions{ All: false, - RegistryAuth: authConfig.Auth, + RegistryAuth: registryAuth, PrivilegeFunc: nil, } // image is a ref here @@ -1256,7 +1260,6 @@ func (e *Engine) RenameContainer(container *Container, newName string) error { // BuildImage builds an image func (e *Engine) BuildImage(buildContext io.Reader, buildImage *types.ImageBuildOptions) (io.ReadCloser, error) { - // TODO(nishanttotla): buildcontext for image could be specific instead of nil resp, err := e.apiClient.ImageBuild(context.Background(), buildContext, *buildImage) e.CheckConnectionErr(err) if err != nil { diff --git a/cluster/engine_test.go b/cluster/engine_test.go index 4b87d31482..82b92fa3a9 100644 --- a/cluster/engine_test.go +++ b/cluster/engine_test.go @@ -353,8 +353,8 @@ func TestCreateContainer(t *testing.T) { id = "id3" apiClient.On("ImageList", mock.Anything, mock.AnythingOfType("ImageListOptions")).Return([]types.Image{}, nil).Once() mockConfig.HostConfig.CPUShares = int64(math.Ceil(float64(config.HostConfig.CPUShares*1024) / float64(mockInfo.NCPU))) - apiClient.On("ImagePull", mock.Anything, types.ImagePullOptions{ImageID: config.Image, Tag: "latest"}, mock.Anything).Return(readCloser, nil).Once() - // FIXMEENGINEAPI : below should return an engine-api error, or something custom + apiClient.On("ImagePull", mock.Anything, config.Image, mock.AnythingOfType("types.ImagePullOptions")).Return(readCloser, nil).Once() + // TODO(nishanttotla): below should return an engine-api error, or something custom, so that we can get rid of dockerclient apiClient.On("ContainerCreate", mock.Anything, &mockConfig.Config, &mockConfig.HostConfig, &mockConfig.NetworkingConfig, name).Return(types.ContainerCreateResponse{}, dockerclient.ErrImageNotFound).Once() // FIXMEENGINEAPI : below should return an engine-api error, or something custom apiClient.On("ContainerCreate", mock.Anything, &mockConfig.Config, &mockConfig.HostConfig, &mockConfig.NetworkingConfig, name).Return(types.ContainerCreateResponse{ID: id}, nil).Once() @@ -531,7 +531,7 @@ func TestRemoveImage(t *testing.T) { apiClient := engineapimock.NewMockClient() apiClient.On("ImageList", mock.Anything, mock.AnythingOfType("ImageListOptions")).Return([]types.Image{}, nil) - apiClient.On("ImageRemove", mock.Anything, + apiClient.On("ImageRemove", mock.Anything, mock.Anything, mock.AnythingOfType("ImageRemoveOptions")).Return(dIs, nil) engine.apiClient = apiClient diff --git a/cluster/swarm/cluster_test.go b/cluster/swarm/cluster_test.go index 0c5acd506c..a524e63447 100644 --- a/cluster/swarm/cluster_test.go +++ b/cluster/swarm/cluster_test.go @@ -155,7 +155,7 @@ func TestImportImage(t *testing.T) { // import success readCloser := nopCloser{bytes.NewBufferString("ok")} - apiClient.On("ImageImport", mock.Anything, mock.AnythingOfType("types.ImageImportOptions")).Return(readCloser, nil).Once() + apiClient.On("ImageImport", mock.Anything, mock.AnythingOfType("types.ImageImportSource"), mock.Anything, mock.AnythingOfType("types.ImageImportOptions")).Return(readCloser, nil).Once() callback := func(what, status string, err error) { // import success @@ -166,7 +166,7 @@ func TestImportImage(t *testing.T) { // import error readCloser = nopCloser{bytes.NewBufferString("error")} err := fmt.Errorf("Import error") - apiClient.On("ImageImport", mock.Anything, mock.AnythingOfType("types.ImageImportOptions")).Return(readCloser, err).Once() + apiClient.On("ImageImport", mock.Anything, mock.AnythingOfType("types.ImageImportSource"), mock.Anything, mock.AnythingOfType("types.ImageImportOptions")).Return(readCloser, err).Once() callback = func(what, status string, err error) { // import error @@ -264,7 +264,7 @@ func TestTagImage(t *testing.T) { c.engines[engine.ID] = engine // tag image - apiClient.On("ImageTag", mock.Anything, mock.AnythingOfType("types.ImageTagOptions")).Return(nil).Once() + apiClient.On("ImageTag", mock.Anything, mock.Anything, mock.Anything, mock.AnythingOfType("types.ImageTagOptions")).Return(nil).Once() assert.Nil(t, c.TagImage("busybox", "test_busybox", "latest", false)) assert.NotNil(t, c.TagImage("busybox_not_exists", "test_busybox", "latest", false)) }