Datasets:
File size: 9,430 Bytes
0e239c6 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 | diff --git a/cli/command/image/load.go b/cli/command/image/load.go
index 4bbf26069e..4fc9394661 100644
--- a/cli/command/image/load.go
+++ b/cli/command/image/load.go
@@ -70,7 +70,7 @@ func runLoad(ctx context.Context, dockerCli command.Cli, opts loadOptions) error
if err != nil {
return err
}
- defer file.Close()
+ defer func() { _ = file.Close() }()
input = file
}
@@ -95,12 +95,7 @@ func runLoad(ctx context.Context, dockerCli command.Cli, opts loadOptions) error
if err != nil {
return err
}
- defer res.Close()
+ defer func() { _ = res.Close() }()
- if res.JSON {
- return jsonstream.Display(ctx, res, dockerCli.Out())
- }
-
- _, err = io.Copy(dockerCli.Out(), res)
- return err
+ return jsonstream.Display(ctx, res, dockerCli.Out())
}
diff --git a/cli/command/image/load_test.go b/cli/command/image/load_test.go
index 91f4273cdd..78c1ca0452 100644
--- a/cli/command/image/load_test.go
+++ b/cli/command/image/load_test.go
@@ -74,8 +74,8 @@ func TestNewLoadCommandInvalidInput(t *testing.T) {
assert.ErrorContains(t, err, expectedError)
}
-func mockImageLoadResult(content string, json bool) client.ImageLoadResult {
- out := client.ImageLoadResult{JSON: json}
+func mockImageLoadResult(content string) client.ImageLoadResult {
+ out := client.ImageLoadResult{}
// Set unexported field "body"
v := reflect.ValueOf(&out).Elem()
@@ -94,22 +94,12 @@ func TestNewLoadCommandSuccess(t *testing.T) {
{
name: "simple",
args: []string{},
- imageLoadFunc: func(input io.Reader, options ...client.ImageLoadOption) (client.ImageLoadResult, error) {
- // FIXME(thaJeztah): how to mock this?
- // return client.ImageLoadResult{Body: io.NopCloser(strings.NewReader("Success"))}, nil
- return mockImageLoadResult(`Success`, false), nil
- },
- },
- {
- name: "json",
- args: []string{},
imageLoadFunc: func(input io.Reader, options ...client.ImageLoadOption) (client.ImageLoadResult, error) {
// FIXME(thaJeztah): how to mock this?
// return client.ImageLoadResult{
- // Body: io.NopCloser(strings.NewReader(`{"ID": "1"}`)),
- // JSON: true,
+ // Body: io.NopCloser(strings.NewReader(`{"ID":"simple","Status":"success"}`)),
// }, nil
- return mockImageLoadResult(`{"ID":"1"}`, true), nil
+ return mockImageLoadResult(`{"ID":"simple","Status":"success"}`), nil
},
},
{
@@ -117,8 +107,8 @@ func TestNewLoadCommandSuccess(t *testing.T) {
args: []string{"--input", "testdata/load-command-success.input.txt"},
imageLoadFunc: func(input io.Reader, options ...client.ImageLoadOption) (client.ImageLoadResult, error) {
// FIXME(thaJeztah): how to mock this?
- // return client.ImageLoadResult{Body: io.NopCloser(strings.NewReader("Success"))}, nil
- return mockImageLoadResult(`Success`, false), nil
+ // return client.ImageLoadResult{Body: io.NopCloser(strings.NewReader(`{"ID":"input-file","Status":"success"}`))}, nil
+ return mockImageLoadResult(`{"ID":"input-file","Status":"success"}`), nil
},
},
{
@@ -129,8 +119,8 @@ func TestNewLoadCommandSuccess(t *testing.T) {
assert.Check(t, len(options) > 0) // can be 1 or two depending on whether a terminal is attached :/
// assert.Check(t, is.Contains(options, client.ImageHistoryWithPlatform(ocispec.Platform{OS: "linux", Architecture: "amd64"})))
// FIXME(thaJeztah): how to mock this?
- // return client.ImageLoadResult{Body: io.NopCloser(strings.NewReader("Success"))}, nil
- return mockImageLoadResult(`Success`, false), nil
+ // return client.ImageLoadResult{Body: io.NopCloser(strings.NewReader(`{"ID":"single-platform","Status":"success"}`))}, nil
+ return mockImageLoadResult(`{"ID":"single-platform","Status":"success"}`), nil
},
},
{
@@ -139,8 +129,8 @@ func TestNewLoadCommandSuccess(t *testing.T) {
imageLoadFunc: func(input io.Reader, options ...client.ImageLoadOption) (client.ImageLoadResult, error) {
assert.Check(t, len(options) > 0) // can be 1 or two depending on whether a terminal is attached :/
// FIXME(thaJeztah): how to mock this?
- // return client.ImageLoadResult{Body: io.NopCloser(strings.NewReader("Success"))}, nil
- return mockImageLoadResult(`Success`, false), nil
+ // return client.ImageLoadResult{Body: io.NopCloser(strings.NewReader(`{"ID":"with-comma-separated-platforms","Status":"success"}`))}, nil
+ return mockImageLoadResult(`{"ID":"with-comma-separated-platforms","Status":"success"}`), nil
},
},
{
@@ -149,8 +139,8 @@ func TestNewLoadCommandSuccess(t *testing.T) {
imageLoadFunc: func(input io.Reader, options ...client.ImageLoadOption) (client.ImageLoadResult, error) {
assert.Check(t, len(options) > 0) // can be 1 or two depending on whether a terminal is attached :/
// FIXME(thaJeztah): how to mock this?
- // return client.ImageLoadResult{Body: io.NopCloser(strings.NewReader("Success"))}, nil
- return mockImageLoadResult(`Success`, false), nil
+ // return client.ImageLoadResult{Body: io.NopCloser(strings.NewReader(`{"ID":"with-multiple-platform-options","Status":"success"}`))}, nil
+ return mockImageLoadResult(`{"ID":"with-multiple-platform-options","Status":"success"}`), nil
},
},
}
diff --git a/cli/command/image/testdata/load-command-success.input-file.golden b/cli/command/image/testdata/load-command-success.input-file.golden
index 51da4200ab..0f454425f4 100644
--- a/cli/command/image/testdata/load-command-success.input-file.golden
+++ b/cli/command/image/testdata/load-command-success.input-file.golden
@@ -1 +1 @@
-Success
\ No newline at end of file
+input-file: success
diff --git a/cli/command/image/testdata/load-command-success.json.golden b/cli/command/image/testdata/load-command-success.json.golden
deleted file mode 100644
index c17f16ecd7..0000000000
--- a/cli/command/image/testdata/load-command-success.json.golden
+++ /dev/null
@@ -1 +0,0 @@
-1:
diff --git a/cli/command/image/testdata/load-command-success.simple.golden b/cli/command/image/testdata/load-command-success.simple.golden
index 51da4200ab..f503a70c61 100644
--- a/cli/command/image/testdata/load-command-success.simple.golden
+++ b/cli/command/image/testdata/load-command-success.simple.golden
@@ -1 +1 @@
-Success
\ No newline at end of file
+simple: success
diff --git a/cli/command/image/testdata/load-command-success.with-comma-separated-platforms.golden b/cli/command/image/testdata/load-command-success.with-comma-separated-platforms.golden
index 51da4200ab..9cd1f6fc34 100644
--- a/cli/command/image/testdata/load-command-success.with-comma-separated-platforms.golden
+++ b/cli/command/image/testdata/load-command-success.with-comma-separated-platforms.golden
@@ -1 +1 @@
-Success
\ No newline at end of file
+with-comma-separated-platforms: success
diff --git a/cli/command/image/testdata/load-command-success.with-multiple-platform-options.golden b/cli/command/image/testdata/load-command-success.with-multiple-platform-options.golden
index 51da4200ab..172a51a1aa 100644
--- a/cli/command/image/testdata/load-command-success.with-multiple-platform-options.golden
+++ b/cli/command/image/testdata/load-command-success.with-multiple-platform-options.golden
@@ -1 +1 @@
-Success
\ No newline at end of file
+with-multiple-platform-options: success
diff --git a/cli/command/image/testdata/load-command-success.with-single-platform.golden b/cli/command/image/testdata/load-command-success.with-single-platform.golden
index 51da4200ab..59ff47762f 100644
--- a/cli/command/image/testdata/load-command-success.with-single-platform.golden
+++ b/cli/command/image/testdata/load-command-success.with-single-platform.golden
@@ -1 +1 @@
-Success
\ No newline at end of file
+single-platform: success
diff --git a/cli/command/telemetry.go b/cli/command/telemetry.go
index f4107c3863..e8e6296b5a 100644
--- a/cli/command/telemetry.go
+++ b/cli/command/telemetry.go
@@ -11,7 +11,6 @@ import (
"github.com/google/uuid"
"go.opentelemetry.io/otel"
"go.opentelemetry.io/otel/metric"
- otelsdk "go.opentelemetry.io/otel/sdk"
sdkmetric "go.opentelemetry.io/otel/sdk/metric"
"go.opentelemetry.io/otel/sdk/metric/metricdata"
"go.opentelemetry.io/otel/sdk/resource"
@@ -147,7 +146,7 @@ func defaultResourceOptions() []resource.Option {
semconv.ServiceInstanceID(uuid.NewString()),
),
resource.WithFromEnv(),
- resource.WithDetectors(telemetrySDK{}),
+ resource.WithTelemetrySDK(),
}
}
@@ -158,10 +157,7 @@ func (r *telemetryResource) AppendOptions(opts ...resource.Option) {
r.opts = append(r.opts, opts...)
}
-type (
- serviceNameDetector struct{}
- telemetrySDK struct{}
-)
+type serviceNameDetector struct{}
func (serviceNameDetector) Detect(ctx context.Context) (*resource.Resource, error) {
return resource.StringDetector(
@@ -173,16 +169,6 @@ func (serviceNameDetector) Detect(ctx context.Context) (*resource.Resource, erro
).Detect(ctx)
}
-// Detect returns a *Resource that describes the OpenTelemetry SDK used.
-func (telemetrySDK) Detect(context.Context) (*resource.Resource, error) {
- return resource.NewWithAttributes(
- semconv.SchemaURL,
- semconv.TelemetrySDKName("opentelemetry"),
- semconv.TelemetrySDKLanguageGo,
- semconv.TelemetrySDKVersion(otelsdk.Version()),
- ), nil
-}
-
// cliReader is an implementation of Reader that will automatically
// report to a designated Exporter when Shutdown is called.
type cliReader struct {
|