diff options
| author | 2023-04-28 01:36:44 +0800 | |
|---|---|---|
| committer | 2023-04-28 01:36:44 +0800 | |
| commit | dd84b9d64fb98746a230cd24233ff50a562c39c9 (patch) | |
| tree | b583261ef00b3afe72ec4d6dacb31e57779a6faf /cli/internal/cacheitem/restore_directory_test.go | |
| parent | 0b46fcd72ac34382387b2bcf9095233efbcc52f4 (diff) | |
| download | HydroRoll-dd84b9d64fb98746a230cd24233ff50a562c39c9.tar.gz HydroRoll-dd84b9d64fb98746a230cd24233ff50a562c39c9.zip | |
Diffstat (limited to 'cli/internal/cacheitem/restore_directory_test.go')
| -rw-r--r-- | cli/internal/cacheitem/restore_directory_test.go | 103 |
1 files changed, 103 insertions, 0 deletions
diff --git a/cli/internal/cacheitem/restore_directory_test.go b/cli/internal/cacheitem/restore_directory_test.go new file mode 100644 index 0000000..f75bd47 --- /dev/null +++ b/cli/internal/cacheitem/restore_directory_test.go @@ -0,0 +1,103 @@ +package cacheitem + +import ( + "reflect" + "testing" + + "github.com/vercel/turbo/cli/internal/turbopath" +) + +func Test_cachedDirTree_getStartingPoint(t *testing.T) { + testDir := turbopath.AbsoluteSystemPath("") + tests := []struct { + name string + + // STATE + cachedDirTree cachedDirTree + + // INPUT + path turbopath.AnchoredSystemPath + + // OUTPUT + calculatedAnchor turbopath.AbsoluteSystemPath + pathSegments []turbopath.RelativeSystemPath + }{ + { + name: "hello world", + cachedDirTree: cachedDirTree{ + anchorAtDepth: []turbopath.AbsoluteSystemPath{testDir}, + prefix: []turbopath.RelativeSystemPath{}, + }, + path: turbopath.AnchoredUnixPath("hello/world").ToSystemPath(), + calculatedAnchor: testDir, + pathSegments: []turbopath.RelativeSystemPath{"hello", "world"}, + }, + { + name: "has a cache", + cachedDirTree: cachedDirTree{ + anchorAtDepth: []turbopath.AbsoluteSystemPath{ + testDir, + testDir.UntypedJoin("hello"), + }, + prefix: []turbopath.RelativeSystemPath{"hello"}, + }, + path: turbopath.AnchoredUnixPath("hello/world").ToSystemPath(), + calculatedAnchor: testDir.UntypedJoin("hello"), + pathSegments: []turbopath.RelativeSystemPath{"world"}, + }, + { + name: "ask for yourself", + cachedDirTree: cachedDirTree{ + anchorAtDepth: []turbopath.AbsoluteSystemPath{ + testDir, + testDir.UntypedJoin("hello"), + testDir.UntypedJoin("hello", "world"), + }, + prefix: []turbopath.RelativeSystemPath{"hello", "world"}, + }, + path: turbopath.AnchoredUnixPath("hello/world").ToSystemPath(), + calculatedAnchor: testDir.UntypedJoin("hello", "world"), + pathSegments: []turbopath.RelativeSystemPath{}, + }, + { + name: "three layer cake", + cachedDirTree: cachedDirTree{ + anchorAtDepth: []turbopath.AbsoluteSystemPath{ + testDir, + testDir.UntypedJoin("hello"), + testDir.UntypedJoin("hello", "world"), + }, + prefix: []turbopath.RelativeSystemPath{"hello", "world"}, + }, + path: turbopath.AnchoredUnixPath("hello/world/again").ToSystemPath(), + calculatedAnchor: testDir.UntypedJoin("hello", "world"), + pathSegments: []turbopath.RelativeSystemPath{"again"}, + }, + { + name: "outside of cache hierarchy", + cachedDirTree: cachedDirTree{ + anchorAtDepth: []turbopath.AbsoluteSystemPath{ + testDir, + testDir.UntypedJoin("hello"), + testDir.UntypedJoin("hello", "world"), + }, + prefix: []turbopath.RelativeSystemPath{"hello", "world"}, + }, + path: turbopath.AnchoredUnixPath("somewhere/else").ToSystemPath(), + calculatedAnchor: testDir, + pathSegments: []turbopath.RelativeSystemPath{"somewhere", "else"}, + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + cr := tt.cachedDirTree + calculatedAnchor, pathSegments := cr.getStartingPoint(tt.path) + if !reflect.DeepEqual(calculatedAnchor, tt.calculatedAnchor) { + t.Errorf("cachedDirTree.getStartingPoint() calculatedAnchor = %v, want %v", calculatedAnchor, tt.calculatedAnchor) + } + if !reflect.DeepEqual(pathSegments, tt.pathSegments) { + t.Errorf("cachedDirTree.getStartingPoint() pathSegments = %v, want %v", pathSegments, tt.pathSegments) + } + }) + } +} |
