Skip to content

Commit

Permalink
Silence a "potentially unused parameter" warning
Browse files Browse the repository at this point in the history
configBlobImageSource.f is only called if the digest
is exactly one value, so the function doesn't need to
use it (and none of them do).  So, remove it; this also
drops a recently-introduced warning in VS Code.

Should not change (test) behavior.

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
  • Loading branch information
mtrmac committed Jul 20, 2022
1 parent 81eae1e commit f4febfc
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 15 deletions.
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

0 comments on commit f4febfc

Please sign in to comment.