File: subscriptions_test.go

package info (click to toggle)
golang-github-containers-common 0.56.0%2Bds1-4
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 4,852 kB
  • sloc: makefile: 126; sh: 62
file content (32 lines) | stat: -rw-r--r-- 802 bytes parent folder | download | duplicates (3)
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
package subscriptions

import (
	"os"
	"path/filepath"
	"testing"

	"github.com/stretchr/testify/assert"
)

func TestReadAllAndSaveTo(t *testing.T) {
	const testMode = os.FileMode(0o700)

	rootDir := t.TempDir()
	childDir := filepath.Join(rootDir, "child")
	err := os.Mkdir(childDir, testMode)
	assert.NoError(t, err, "mkdir child")

	filePath := "child/file"
	err = os.WriteFile(filepath.Join(rootDir, filePath), []byte("test"), testMode)
	assert.NoError(t, err, "write file")

	data, err := readAll(rootDir, "", testMode)
	assert.NoError(t, err, "readAll")
	assert.Len(t, data, 1, "readAll should return one result")

	tmpDir := t.TempDir()
	err = data[0].saveTo(tmpDir)
	assert.NoError(t, err, "saveTo()")

	assert.FileExists(t, filepath.Join(tmpDir, filePath), "file exists at correct location")
}