MCPcopy Create free account
hub / github.com/containers/image / runPathResolvingTestCase

Function runPathResolvingTestCase

directory/explicitfilepath/path_test.go:126–159  ·  view source on GitHub ↗
(t *testing.T, f func(string) (string, error), c pathResolvingTestCase, suffix string)

Source from the content-addressed store, hash-verified

124}
125
126func runPathResolvingTestCase(t *testing.T, f func(string) (string, error), c pathResolvingTestCase, suffix string) {
127 topDir := t.TempDir()
128 defer func() {
129 // Clean up after the "Unreadable directory" case; os.RemoveAll just fails without this.
130 _ = os.Chmod(filepath.Join(topDir, "unreadable"), 0755) // Ignore errors, especially if this does not exist.
131 }()
132
133 input := c.setup(t, topDir) + suffix // Do not call filepath.Join() on input, it calls filepath.Clean() internally!
134 description := fmt.Sprintf("%s vs. %s%s", input, c.expected, suffix)
135
136 fullOutput, err := f(topDir + "/" + input)
137 if c.expected == "" {
138 assert.Error(t, err, description)
139 } else {
140 require.NoError(t, err, input)
141 fullExpected := topDir + "/" + c.expected + suffix
142 assert.Equal(t, fullExpected, fullOutput)
143
144 // Either the two paths resolve to the same existing file, or to the same name in the same existing parent.
145 if _, err := os.Lstat(fullExpected); err == nil {
146 testPathsAreSameFile(t, fullOutput, fullExpected, description)
147 } else {
148 require.True(t, os.IsNotExist(err))
149 _, err := os.Stat(fullOutput)
150 require.Error(t, err)
151 require.True(t, os.IsNotExist(err))
152
153 parentExpected, fileExpected := filepath.Split(fullExpected)
154 parentOutput, fileOutput := filepath.Split(fullOutput)
155 assert.Equal(t, fileExpected, fileOutput)
156 testPathsAreSameFile(t, parentOutput, parentExpected, description)
157 }
158 }
159}
160
161func TestResolvePathToFullyExplicit(t *testing.T) {
162 for _, c := range testCases {

Calls 2

testPathsAreSameFileFunction · 0.85
ErrorMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…