2017-09-26 18:15:04 -04:00
|
|
|
package manifest
|
|
|
|
|
|
|
|
import (
|
2018-05-03 21:02:44 -04:00
|
|
|
"context"
|
2022-02-25 07:11:27 -05:00
|
|
|
"io"
|
2017-09-26 18:15:04 -04:00
|
|
|
"testing"
|
|
|
|
|
2022-02-25 07:11:27 -05:00
|
|
|
"github.com/docker/cli/cli/manifest/store"
|
2017-09-26 18:15:04 -04:00
|
|
|
manifesttypes "github.com/docker/cli/cli/manifest/types"
|
|
|
|
"github.com/docker/cli/internal/test"
|
|
|
|
"github.com/docker/distribution/reference"
|
|
|
|
"github.com/pkg/errors"
|
2020-02-22 12:12:14 -05:00
|
|
|
"gotest.tools/v3/assert"
|
2017-09-26 18:15:04 -04:00
|
|
|
)
|
|
|
|
|
2018-03-08 13:20:42 -05:00
|
|
|
func newFakeRegistryClient() *fakeRegistryClient {
|
2017-09-26 18:15:04 -04:00
|
|
|
return &fakeRegistryClient{
|
|
|
|
getManifestFunc: func(_ context.Context, _ reference.Named) (manifesttypes.ImageManifest, error) {
|
|
|
|
return manifesttypes.ImageManifest{}, errors.New("")
|
|
|
|
},
|
|
|
|
getManifestListFunc: func(_ context.Context, _ reference.Named) ([]manifesttypes.ImageManifest, error) {
|
|
|
|
return nil, errors.Errorf("")
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestManifestPushErrors(t *testing.T) {
|
|
|
|
testCases := []struct {
|
|
|
|
args []string
|
|
|
|
expectedError string
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
args: []string{"one-arg", "extra-arg"},
|
|
|
|
expectedError: "requires exactly 1 argument",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
args: []string{"th!si'sa/fa!ke/li$t/-name"},
|
|
|
|
expectedError: "invalid reference format",
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, tc := range testCases {
|
|
|
|
cli := test.NewFakeCli(nil)
|
|
|
|
cmd := newPushListCommand(cli)
|
|
|
|
cmd.SetArgs(tc.args)
|
2022-02-25 07:11:27 -05:00
|
|
|
cmd.SetOut(io.Discard)
|
2018-03-06 14:03:47 -05:00
|
|
|
assert.ErrorContains(t, cmd.Execute(), tc.expectedError)
|
2017-09-26 18:15:04 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestManifestPush(t *testing.T) {
|
2022-02-25 07:11:27 -05:00
|
|
|
store := store.NewStore(t.TempDir())
|
2017-09-26 18:15:04 -04:00
|
|
|
|
2018-03-08 13:20:42 -05:00
|
|
|
registry := newFakeRegistryClient()
|
2017-09-26 18:15:04 -04:00
|
|
|
|
|
|
|
cli := test.NewFakeCli(nil)
|
|
|
|
cli.SetManifestStore(store)
|
|
|
|
cli.SetRegistryClient(registry)
|
|
|
|
|
|
|
|
namedRef := ref(t, "alpine:3.0")
|
|
|
|
imageManifest := fullImageManifest(t, namedRef)
|
|
|
|
err := store.Save(ref(t, "list:v1"), namedRef, imageManifest)
|
2018-03-05 18:53:52 -05:00
|
|
|
assert.NilError(t, err)
|
2017-09-26 18:15:04 -04:00
|
|
|
|
|
|
|
cmd := newPushListCommand(cli)
|
|
|
|
cmd.SetArgs([]string{"example.com/list:v1"})
|
|
|
|
err = cmd.Execute()
|
2018-03-05 18:53:52 -05:00
|
|
|
assert.NilError(t, err)
|
2017-09-26 18:15:04 -04:00
|
|
|
}
|