2018-03-19 18:56:51 -04:00
|
|
|
package containerizedengine
|
|
|
|
|
|
|
|
import (
|
2018-09-11 08:46:30 -04:00
|
|
|
"bytes"
|
2018-03-19 18:56:51 -04:00
|
|
|
"context"
|
|
|
|
"fmt"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/containerd/containerd"
|
2019-01-28 08:30:31 -05:00
|
|
|
"github.com/docker/cli/cli/streams"
|
2018-03-19 18:56:51 -04:00
|
|
|
"github.com/docker/docker/api/types"
|
2020-02-22 12:12:14 -05:00
|
|
|
"gotest.tools/v3/assert"
|
2018-03-19 18:56:51 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestPullWithAuthPullFail(t *testing.T) {
|
|
|
|
ctx := context.Background()
|
|
|
|
client := baseClient{
|
|
|
|
cclient: &fakeContainerdClient{
|
|
|
|
pullFunc: func(ctx context.Context, ref string, opts ...containerd.RemoteOpt) (containerd.Image, error) {
|
|
|
|
return nil, fmt.Errorf("pull failure")
|
|
|
|
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
imageName := "testnamegoeshere"
|
|
|
|
|
2019-01-28 08:30:31 -05:00
|
|
|
_, err := client.pullWithAuth(ctx, imageName, streams.NewOut(&bytes.Buffer{}), &types.AuthConfig{})
|
2018-03-19 18:56:51 -04:00
|
|
|
assert.ErrorContains(t, err, "pull failure")
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestPullWithAuthPullPass(t *testing.T) {
|
|
|
|
ctx := context.Background()
|
|
|
|
client := baseClient{
|
|
|
|
cclient: &fakeContainerdClient{
|
|
|
|
pullFunc: func(ctx context.Context, ref string, opts ...containerd.RemoteOpt) (containerd.Image, error) {
|
|
|
|
return nil, nil
|
|
|
|
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
imageName := "testnamegoeshere"
|
|
|
|
|
2019-01-28 08:30:31 -05:00
|
|
|
_, err := client.pullWithAuth(ctx, imageName, streams.NewOut(&bytes.Buffer{}), &types.AuthConfig{})
|
2018-03-19 18:56:51 -04:00
|
|
|
assert.NilError(t, err)
|
|
|
|
}
|