github.1git.de/docker/cli@v26.1.3+incompatible/cli/command/plugin/upgrade_test.go (about)

     1  package plugin
     2  
     3  import (
     4  	"context"
     5  	"io"
     6  	"testing"
     7  
     8  	"github.com/docker/cli/internal/test"
     9  	"github.com/docker/docker/api/types"
    10  	"github.com/pkg/errors"
    11  	"gotest.tools/v3/golden"
    12  )
    13  
    14  func TestUpgradePromptTermination(t *testing.T) {
    15  	ctx, cancel := context.WithCancel(context.Background())
    16  	t.Cleanup(cancel)
    17  
    18  	cli := test.NewFakeCli(&fakeClient{
    19  		pluginUpgradeFunc: func(name string, options types.PluginInstallOptions) (io.ReadCloser, error) {
    20  			return nil, errors.New("should not be called")
    21  		},
    22  		pluginInspectFunc: func(name string) (*types.Plugin, []byte, error) {
    23  			return &types.Plugin{
    24  				ID:              "5724e2c8652da337ab2eedd19fc6fc0ec908e4bd907c7421bf6a8dfc70c4c078",
    25  				Name:            "foo/bar",
    26  				Enabled:         false,
    27  				PluginReference: "localhost:5000/foo/bar:v0.1.0",
    28  			}, []byte{}, nil
    29  		},
    30  	})
    31  	cmd := newUpgradeCommand(cli)
    32  	// need to set a remote address that does not match the plugin
    33  	// reference sent by the `pluginInspectFunc`
    34  	cmd.SetArgs([]string{"foo/bar", "localhost:5000/foo/bar:v1.0.0"})
    35  	test.TerminatePrompt(ctx, t, cmd, cli)
    36  	golden.Assert(t, cli.OutBuffer().String(), "plugin-upgrade-terminate.golden")
    37  }