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
|
package copy
import (
"fmt"
"testing"
"github.com/containers/image/v5/internal/private"
"github.com/containers/image/v5/pkg/compression"
"github.com/containers/image/v5/types"
imgspecv1 "github.com/opencontainers/image-spec/specs-go/v1"
"github.com/stretchr/testify/assert"
)
func TestUpdatedBlobInfoFromUpload(t *testing.T) {
for _, c := range []struct {
srcInfo types.BlobInfo
uploaded private.UploadedBlob
expected types.BlobInfo
}{
{ // A straightforward upload with a known size
srcInfo: types.BlobInfo{
Digest: "sha256:6a5a5368e0c2d3e5909184fa28ddfd56072e7ff3ee9a945876f7eee5896ef5bb",
Size: 51354364,
URLs: []string{"https://layer.url"},
Annotations: map[string]string{"test-annotation-2": "two"},
MediaType: imgspecv1.MediaTypeImageLayerGzip,
CompressionOperation: types.Compress, // Might be set by blobCacheSource.LayerInfosForCopy
CompressionAlgorithm: &compression.Gzip, // Set e.g. in copyLayer
// CryptoOperation is not set by LayerInfos()
},
uploaded: private.UploadedBlob{
Digest: "sha256:6a5a5368e0c2d3e5909184fa28ddfd56072e7ff3ee9a945876f7eee5896ef5bb",
Size: 51354364,
},
expected: types.BlobInfo{
Digest: "sha256:6a5a5368e0c2d3e5909184fa28ddfd56072e7ff3ee9a945876f7eee5896ef5bb",
Size: 51354364,
URLs: nil,
Annotations: map[string]string{"test-annotation-2": "two"},
MediaType: imgspecv1.MediaTypeImageLayerGzip,
CompressionOperation: types.Compress, // Might be set by blobCacheSource.LayerInfosForCopy
CompressionAlgorithm: &compression.Gzip, // Set e.g. in copyLayer
// CryptoOperation is set to the zero value
},
},
{ // Upload determining the digest/size
srcInfo: types.BlobInfo{
Digest: "",
Size: -1,
URLs: []string{"https://layer.url"},
Annotations: map[string]string{"test-annotation-2": "two"},
MediaType: imgspecv1.MediaTypeImageLayerGzip,
CompressionOperation: types.Compress, // Might be set by blobCacheSource.LayerInfosForCopy
CompressionAlgorithm: &compression.Gzip, // Set e.g. in copyLayer
// CryptoOperation is not set by LayerInfos()
},
uploaded: private.UploadedBlob{
Digest: "sha256:aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
Size: 513543640,
},
expected: types.BlobInfo{
Digest: "sha256:aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
Size: 513543640,
URLs: nil,
Annotations: map[string]string{"test-annotation-2": "two"},
MediaType: imgspecv1.MediaTypeImageLayerGzip,
CompressionOperation: types.Compress, // Might be set by blobCacheSource.LayerInfosForCopy
CompressionAlgorithm: &compression.Gzip, // Set e.g. in copyLayer
// CryptoOperation is set to the zero value
},
},
} {
res := updatedBlobInfoFromUpload(c.srcInfo, c.uploaded)
assert.Equal(t, c.expected, res, fmt.Sprintf("%#v", c.uploaded))
}
}
|