(t *testing.T)
| 193 | } |
| 194 | |
| 195 | func TestPinFile(t *testing.T) { |
| 196 | defer ClearMappings() |
| 197 | create := mockNewFs(t) |
| 198 | |
| 199 | // Test pinning and unpinning nonexistent |
| 200 | f, err := mockfs.NewFs(context.Background(), "mock", "/file.txt", nil) |
| 201 | require.NoError(t, err) |
| 202 | Pin(f) |
| 203 | Unpin(f) |
| 204 | |
| 205 | // Now test pinning an existing |
| 206 | f2, err := GetFn(context.Background(), "mock:/file.txt", create) |
| 207 | require.Equal(t, fs.ErrorIsFile, err) |
| 208 | assert.Equal(t, 1, len(childParentMap)) |
| 209 | |
| 210 | Pin(f2) |
| 211 | assert.Equal(t, 1, Entries()) |
| 212 | pinned, unpinned := EntriesWithPinCount() |
| 213 | assert.Equal(t, 1, pinned) |
| 214 | assert.Equal(t, 0, unpinned) |
| 215 | |
| 216 | Unpin(f2) |
| 217 | assert.Equal(t, 1, Entries()) |
| 218 | pinned, unpinned = EntriesWithPinCount() |
| 219 | assert.Equal(t, 0, pinned) |
| 220 | assert.Equal(t, 1, unpinned) |
| 221 | |
| 222 | // try a different child of the same parent, and parent |
| 223 | // should not add additional cache items |
| 224 | called = 0 // this one does create() because we haven't seen it before and don't yet know it's a file |
| 225 | f3, err := GetFn(context.Background(), "mock:/file2.txt", create) |
| 226 | assert.Equal(t, fs.ErrorIsFile, err) |
| 227 | assert.Equal(t, 1, Entries()) |
| 228 | assert.Equal(t, 2, len(childParentMap)) |
| 229 | |
| 230 | parent, err := GetFn(context.Background(), "mock:/", create) |
| 231 | assert.NoError(t, err) |
| 232 | assert.Equal(t, 1, Entries()) |
| 233 | assert.Equal(t, 2, len(childParentMap)) |
| 234 | |
| 235 | Pin(f3) |
| 236 | assert.Equal(t, 1, Entries()) |
| 237 | pinned, unpinned = EntriesWithPinCount() |
| 238 | assert.Equal(t, 1, pinned) |
| 239 | assert.Equal(t, 0, unpinned) |
| 240 | |
| 241 | Unpin(f3) |
| 242 | assert.Equal(t, 1, Entries()) |
| 243 | pinned, unpinned = EntriesWithPinCount() |
| 244 | assert.Equal(t, 0, pinned) |
| 245 | assert.Equal(t, 1, unpinned) |
| 246 | |
| 247 | Pin(parent) |
| 248 | assert.Equal(t, 1, Entries()) |
| 249 | pinned, unpinned = EntriesWithPinCount() |
| 250 | assert.Equal(t, 1, pinned) |
| 251 | assert.Equal(t, 0, unpinned) |
| 252 |
nothing calls this directly
no test coverage detected
searching dependent graphs…