|
1 | 1 | package image |
2 | 2 |
|
3 | 3 | import ( |
| 4 | + "bytes" |
| 5 | + "context" |
| 6 | + "encoding/json" |
4 | 7 | "errors" |
5 | 8 | "io" |
6 | 9 | "net/http" |
| 10 | + "strings" |
7 | 11 | "testing" |
8 | 12 |
|
9 | 13 | "github.com/docker/cli/internal/test" |
| 14 | + "github.com/moby/moby/api/types/auxprogress" |
10 | 15 | "github.com/moby/moby/client" |
| 16 | + ocispec "github.com/opencontainers/image-spec/specs-go/v1" |
11 | 17 | "gotest.tools/v3/assert" |
12 | 18 | ) |
13 | 19 |
|
@@ -86,3 +92,30 @@ func TestNewPushCommandSuccess(t *testing.T) { |
86 | 92 | }) |
87 | 93 | } |
88 | 94 | } |
| 95 | + |
| 96 | +func TestRunPushRespectsNoColorForAuxNotes(t *testing.T) { |
| 97 | + t.Setenv("NO_COLOR", "1") |
| 98 | + cli := test.NewFakeCli(&fakeClient{ |
| 99 | + imagePushFunc: func(ref string, options client.ImagePushOptions) (client.ImagePushResponse, error) { |
| 100 | + aux, err := json.Marshal(auxprogress.ManifestPushedInsteadOfIndex{ |
| 101 | + ManifestPushedInsteadOfIndex: true, |
| 102 | + OriginalIndex: ocispec.Descriptor{Digest: "sha256:1111111111111111111111111111111111111111111111111111111111111111"}, |
| 103 | + SelectedManifest: ocispec.Descriptor{Digest: "sha256:2222222222222222222222222222222222222222222222222222222222222222"}, |
| 104 | + }) |
| 105 | + assert.NilError(t, err) |
| 106 | + line := append([]byte(`{"aux":`), aux...) |
| 107 | + line = append(line, '}', '\n') |
| 108 | + return fakeStreamResult{ReadCloser: io.NopCloser(bytes.NewReader(line))}, nil |
| 109 | + }, |
| 110 | + }) |
| 111 | + cli.Out().SetIsTerminal(true) |
| 112 | + notes = nil |
| 113 | + t.Cleanup(func() { notes = nil }) |
| 114 | + |
| 115 | + err := runPush(context.Background(), cli, pushOptions{remote: "image:tag"}) |
| 116 | + assert.NilError(t, err) |
| 117 | + |
| 118 | + out := cli.OutBuffer().String() |
| 119 | + assert.Assert(t, strings.Contains(out, "sha256:1111111111111111111111111111111111111111111111111111111111111111 -> sha256:2222222222222222222222222222222222222222222222222222222222222222")) |
| 120 | + assert.Assert(t, !strings.Contains(out, "\x1b["), "output should not contain ANSI escape codes, output: %s", out) |
| 121 | +} |
0 commit comments