Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use strings.NewReader instead of bytes.NewBufferString #1517

Merged
merged 1 commit into from Apr 25, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 1 addition & 2 deletions docker/docker_client.go
@@ -1,7 +1,6 @@
package docker

import (
"bytes"
"context"
"crypto/tls"
"encoding/json"
Expand Down Expand Up @@ -653,7 +652,7 @@ func (c *dockerClient) getBearerTokenOAuth2(ctx context.Context, challenge chall
params.Add("refresh_token", c.auth.IdentityToken)
params.Add("client_id", "containers/image")

authReq.Body = io.NopCloser(bytes.NewBufferString(params.Encode()))
authReq.Body = io.NopCloser(strings.NewReader(params.Encode()))
authReq.Header.Add("User-Agent", c.userAgent)
authReq.Header.Add("Content-Type", "application/x-www-form-urlencoded")
logrus.Debugf("%s %s", authReq.Method, authReq.URL.Redacted())
Expand Down
3 changes: 2 additions & 1 deletion docker/internal/tarfile/src_test.go
Expand Up @@ -4,6 +4,7 @@ import (
"bytes"
"context"
"io"
"strings"
"testing"

"github.com/containers/image/v5/manifest"
Expand All @@ -29,7 +30,7 @@ func TestSourcePrepareLayerData(t *testing.T) {
writer := NewWriter(&tarfileBuffer)
dest := NewDestination(nil, writer, nil)
// No layers
configInfo, err := dest.PutBlob(ctx, bytes.NewBufferString(c.config),
configInfo, err := dest.PutBlob(ctx, strings.NewReader(c.config),
types.BlobInfo{Size: -1}, cache, true)
require.NoError(t, err, c.config)
manifest, err := manifest.Schema2FromComponents(
Expand Down
4 changes: 2 additions & 2 deletions storage/storage_test.go
Expand Up @@ -389,7 +389,7 @@ func TestWriteRead(t *testing.T) {
t.Fatalf("Error saving randomly-generated layer to destination: %v", err)
}
t.Logf("Wrote randomly-generated layer %q (%d/%d bytes) to destination", digest, size, decompressedSize)
if _, err := dest.PutBlob(context.Background(), bytes.NewBufferString(config), configInfo, cache, false); err != nil {
if _, err := dest.PutBlob(context.Background(), strings.NewReader(config), configInfo, cache, false); err != nil {
t.Fatalf("Error saving config to destination: %v", err)
}
manifest := strings.Replace(manifestFmt, "%lh", digest.String(), -1)
Expand Down Expand Up @@ -908,7 +908,7 @@ func TestSize(t *testing.T) {
if dest == nil {
t.Fatalf("NewImageDestination(%q) returned no destination", ref.StringWithinTransport())
}
if _, err := dest.PutBlob(context.Background(), bytes.NewBufferString(config), configInfo, cache, false); err != nil {
if _, err := dest.PutBlob(context.Background(), strings.NewReader(config), configInfo, cache, false); err != nil {
t.Fatalf("Error saving config to destination: %v", err)
}
digest1, usize1, size1, blob := makeLayer(t, archive.Gzip)
Expand Down