github.com/AliyunContainerService/cli@v0.0.0-20181009023821-814ced4b30d0/internal/containerizedengine/containerd_test.go (about)

     1  package containerizedengine
     2  
     3  import (
     4  	"bytes"
     5  	"context"
     6  	"fmt"
     7  	"testing"
     8  
     9  	"github.com/containerd/containerd"
    10  	"github.com/docker/cli/cli/command"
    11  	"github.com/docker/docker/api/types"
    12  	"gotest.tools/assert"
    13  )
    14  
    15  func TestPullWithAuthPullFail(t *testing.T) {
    16  	ctx := context.Background()
    17  	client := baseClient{
    18  		cclient: &fakeContainerdClient{
    19  			pullFunc: func(ctx context.Context, ref string, opts ...containerd.RemoteOpt) (containerd.Image, error) {
    20  				return nil, fmt.Errorf("pull failure")
    21  
    22  			},
    23  		},
    24  	}
    25  	imageName := "testnamegoeshere"
    26  
    27  	_, err := client.pullWithAuth(ctx, imageName, command.NewOutStream(&bytes.Buffer{}), &types.AuthConfig{})
    28  	assert.ErrorContains(t, err, "pull failure")
    29  }
    30  
    31  func TestPullWithAuthPullPass(t *testing.T) {
    32  	ctx := context.Background()
    33  	client := baseClient{
    34  		cclient: &fakeContainerdClient{
    35  			pullFunc: func(ctx context.Context, ref string, opts ...containerd.RemoteOpt) (containerd.Image, error) {
    36  				return nil, nil
    37  
    38  			},
    39  		},
    40  	}
    41  	imageName := "testnamegoeshere"
    42  
    43  	_, err := client.pullWithAuth(ctx, imageName, command.NewOutStream(&bytes.Buffer{}), &types.AuthConfig{})
    44  	assert.NilError(t, err)
    45  }