File: oci_dest_test.go

package info (click to toggle)
golang-github-containers-image 5.36.1-1
  • links: PTS, VCS
  • area: main
  • in suites: experimental
  • size: 5,152 kB
  • sloc: sh: 267; makefile: 100
file content (45 lines) | stat: -rw-r--r-- 1,006 bytes parent folder | download
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
package archive

import (
	"archive/tar"
	"io"
	"os"
	"path/filepath"
	"testing"

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

var _ private.ImageDestination = (*ociArchiveImageDestination)(nil)

func TestTarDirectory(t *testing.T) {
	srcDir := t.TempDir()
	err := os.WriteFile(filepath.Join(srcDir, "regular"), []byte("contents"), 0o600)
	require.NoError(t, err)

	dest := filepath.Join(t.TempDir(), "file.tar")
	err = tarDirectory(srcDir, dest, nil)
	require.NoError(t, err)

	f, err := os.Open(dest)
	require.NoError(t, err)
	defer f.Close()
	reader := tar.NewReader(f)
	numItems := 0
	for {
		hdr, err := reader.Next()
		if err == io.EOF {
			break
		}
		require.NoError(t, err)
		// Test that the header does not expose data about the local account
		assert.Equal(t, 0, hdr.Uid)
		assert.Equal(t, 0, hdr.Gid)
		assert.Empty(t, hdr.Uname)
		assert.Empty(t, hdr.Gname)
		numItems++
	}
	assert.Equal(t, 1, numItems)
}