Datasets:
Download instances/cloudnative-docker-cli-6580/gold/cli.patch from CrossSWE/CrossSWE-Bench: direct link, hf CLI and curl.
- Browser
- Download file 9.43 kB
-
https://huggingface.co/datasets/CrossSWE/CrossSWE-Bench/resolve/main/instances/cloudnative-docker-cli-6580/gold/cli.patch
- Command line
-
hf download hf://datasets/CrossSWE/CrossSWE-Bench/instances/cloudnative-docker-cli-6580/gold/cli.patch
-
curl -L -o cli.patch https://huggingface.co/datasets/CrossSWE/CrossSWE-Bench/resolve/main/instances/cloudnative-docker-cli-6580/gold/cli.patch
9.43 kB
| 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 | |
| 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 | |
| } | |
| 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 | |
| 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() | |
| 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 | |
| }, | |
| }, | |
| { | |
| 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 | |
| }, | |
| }, | |
| { | |
| 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 | |
| }, | |
| }, | |
| { | |
| 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 | |
| }, | |
| }, | |
| { | |
| 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 | |
| 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" | |
| func defaultResourceOptions() []resource.Option { | |
| semconv.ServiceInstanceID(uuid.NewString()), | |
| ), | |
| resource.WithFromEnv(), | |
| - resource.WithDetectors(telemetrySDK{}), | |
| + resource.WithTelemetrySDK(), | |
| } | |
| } | |
| 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( | |
| 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 { | |