File: fsutil_test.go

package info (click to toggle)
docker.io 27.5.1%2Bdfsg4-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 67,384 kB
  • sloc: sh: 5,847; makefile: 1,146; ansic: 664; python: 162; asm: 133
file content (31 lines) | stat: -rw-r--r-- 923 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
package util

import (
	"path"
	"testing"

	"github.com/stretchr/testify/require"
	"github.com/tonistiigi/fsutil"
)

// TestSetErrorPath ensures that modifying the os.PathError from fsutil.Stat
// modifies the error message appropriately.
//
// This method of modifying the path error is an implementation
// detail of how the error is returned. It isn't necessarily the
// case that this will always work if the underlying library changes.
func TestSetErrorPath(t *testing.T) {
	// Temporary directory to reduce the chance of using stat on a real file.
	dir := t.TempDir()

	// Random path that shouldn't exist.
	fpath := path.Join(dir, "a/b/c")
	_, err := fsutil.Stat(fpath)
	require.Error(t, err)

	require.ErrorContains(t, err, "a/b/c")
	// Set the path in the error to a new path.
	replaceErrorPath(err, "/my/new/path")
	require.NotContains(t, err.Error(), "a/b/c")
	require.Contains(t, err.Error(), "/my/new/path")
}