File: stream_digest_test.go

package info (click to toggle)
golang-github-containers-image 5.28.0-4
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 5,104 kB
  • sloc: sh: 194; makefile: 73
file content (36 lines) | stat: -rw-r--r-- 997 bytes parent folder | download | duplicates (4)
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
package streamdigest

import (
	"io"
	"os"
	"testing"

	"github.com/containers/image/v5/types"
	"github.com/stretchr/testify/assert"
	"github.com/stretchr/testify/require"
)

func TestComputeBlobInfo(t *testing.T) {
	inputInfo := types.BlobInfo{Digest: "", Size: -1}
	fixtureFname := "fixtures/Hello.uncompressed"
	fixtureInfo := types.BlobInfo{Digest: "sha256:185f8db32271fe25f561a6fc938b2e264306ec304eda518007d1764826381969", Size: 5}
	fixtureBytes := []byte("Hello")

	// open fixture
	stream, err := os.Open(fixtureFname)
	require.NoError(t, err, fixtureFname)
	defer stream.Close()

	// fill in Digest and Size for inputInfo
	streamCopy, cleanup, err := ComputeBlobInfo(nil, stream, &inputInfo)
	require.NoError(t, err)
	defer cleanup()

	// ensure inputInfo has been filled in with Digest and Size of fixture
	assert.Equal(t, inputInfo, fixtureInfo)

	// ensure streamCopy is the same as fixture
	b, err := io.ReadAll(streamCopy)
	require.NoError(t, err)
	assert.Equal(t, b, fixtureBytes)
}