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

Silence a "potentially unused parameter" warning #1617

Merged
merged 1 commit into from Jul 21, 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
16 changes: 8 additions & 8 deletions internal/image/docker_schema2_test.go
Expand Up @@ -133,40 +133,40 @@ func TestManifestSchema2ConfigInfo(t *testing.T) {
// configBlobImageSource allows testing various GetBlob behaviors in .ConfigBlob()
type configBlobImageSource struct {
mocks.ForbiddenImageSource // We inherit almost all of the methods, which just panic()
f func(digest digest.Digest) (io.ReadCloser, int64, error)
f func() (io.ReadCloser, int64, error)
}

func (f configBlobImageSource) GetBlob(ctx context.Context, info types.BlobInfo, _ types.BlobInfoCache) (io.ReadCloser, int64, error) {
if info.Digest.String() != "sha256:9ca4bda0a6b3727a6ffcc43e981cad0f24e2ec79d338f6ba325b4dfd0756fb8f" {
panic("Unexpected digest in GetBlob")
}
return f.f(info.Digest)
return f.f()
}

func TestManifestSchema2ConfigBlob(t *testing.T) {
realConfigJSON, err := os.ReadFile("fixtures/schema2-config.json")
require.NoError(t, err)

for _, c := range []struct {
cbISfn func(digest digest.Digest) (io.ReadCloser, int64, error)
cbISfn func() (io.ReadCloser, int64, error)
blob []byte
}{
// Success
{func(digest digest.Digest) (io.ReadCloser, int64, error) {
{func() (io.ReadCloser, int64, error) {
return io.NopCloser(bytes.NewReader(realConfigJSON)), int64(len(realConfigJSON)), nil
}, realConfigJSON},
// Various kinds of failures
{nil, nil},
{func(digest digest.Digest) (io.ReadCloser, int64, error) {
{func() (io.ReadCloser, int64, error) {
return nil, -1, errors.New("Error returned from GetBlob")
}, nil},
{func(digest digest.Digest) (io.ReadCloser, int64, error) {
{func() (io.ReadCloser, int64, error) {
reader, writer := io.Pipe()
err = writer.CloseWithError(errors.New("Expected error reading input in ConfigBlob"))
assert.NoError(t, err)
return reader, 1, nil
}, nil},
{func(digest digest.Digest) (io.ReadCloser, int64, error) {
{func() (io.ReadCloser, int64, error) {
nonmatchingJSON := []byte("This does not match ConfigDescriptor.Digest")
return io.NopCloser(bytes.NewReader(nonmatchingJSON)), int64(len(nonmatchingJSON)), nil
}, nil},
Expand Down Expand Up @@ -330,7 +330,7 @@ func newSchema2ImageSource(t *testing.T, dockerRef string) *schema2ImageSource {

return &schema2ImageSource{
configBlobImageSource: configBlobImageSource{
f: func(digest digest.Digest) (io.ReadCloser, int64, error) {
f: func() (io.ReadCloser, int64, error) {
return io.NopCloser(bytes.NewReader(realConfigJSON)), int64(len(realConfigJSON)), nil
},
},
Expand Down
13 changes: 6 additions & 7 deletions internal/image/oci_test.go
Expand Up @@ -15,7 +15,6 @@ import (
"github.com/containers/image/v5/internal/testing/mocks"
"github.com/containers/image/v5/manifest"
"github.com/containers/image/v5/types"
"github.com/opencontainers/go-digest"
imgspecv1 "github.com/opencontainers/image-spec/specs-go/v1"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
Expand Down Expand Up @@ -142,25 +141,25 @@ func TestManifestOCI1ConfigBlob(t *testing.T) {
require.NoError(t, err)

for _, c := range []struct {
cbISfn func(digest digest.Digest) (io.ReadCloser, int64, error)
cbISfn func() (io.ReadCloser, int64, error)
blob []byte
}{
// Success
{func(digest digest.Digest) (io.ReadCloser, int64, error) {
{func() (io.ReadCloser, int64, error) {
return io.NopCloser(bytes.NewReader(realConfigJSON)), int64(len(realConfigJSON)), nil
}, realConfigJSON},
// Various kinds of failures
{nil, nil},
{func(digest digest.Digest) (io.ReadCloser, int64, error) {
{func() (io.ReadCloser, int64, error) {
return nil, -1, errors.New("Error returned from GetBlob")
}, nil},
{func(digest digest.Digest) (io.ReadCloser, int64, error) {
{func() (io.ReadCloser, int64, error) {
reader, writer := io.Pipe()
err = writer.CloseWithError(errors.New("Expected error reading input in ConfigBlob"))
require.NoError(t, err)
return reader, 1, nil
}, nil},
{func(digest digest.Digest) (io.ReadCloser, int64, error) {
{func() (io.ReadCloser, int64, error) {
nonmatchingJSON := []byte("This does not match ConfigDescriptor.Digest")
return io.NopCloser(bytes.NewReader(nonmatchingJSON)), int64(len(nonmatchingJSON)), nil
}, nil},
Expand Down Expand Up @@ -345,7 +344,7 @@ func newOCI1ImageSource(t *testing.T, dockerRef string) *oci1ImageSource {

return &oci1ImageSource{
configBlobImageSource: configBlobImageSource{
f: func(digest digest.Digest) (io.ReadCloser, int64, error) {
f: func() (io.ReadCloser, int64, error) {
return io.NopCloser(bytes.NewReader(realConfigJSON)), int64(len(realConfigJSON)), nil
},
},
Expand Down