Skip to content

Commit

Permalink
Merge pull request #83 from warptools/catalog-ls-symlinks
Browse files Browse the repository at this point in the history
Loosens restrictions on catalog ls results.
  • Loading branch information
warpfork committed Oct 2, 2023
2 parents 2961a17 + 4f233bf commit a9f4fce
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 3 deletions.
7 changes: 4 additions & 3 deletions pkg/workspace/workspace.go
Original file line number Diff line number Diff line change
Expand Up @@ -258,10 +258,11 @@ func (ws *Workspace) ListCatalogs() ([]string, error) {
// build a list of subdirectories, each is a catalog
var list []string
for _, c := range catalogs {
if c.IsDir() && reCatalogName.MatchString(c.Name()) {
name := c.Name()
list = append(list, name)
if !reCatalogName.MatchString(c.Name()) {
continue
}
name := c.Name()
list = append(list, name)
}
return list, nil
}
Expand Down
24 changes: 24 additions & 0 deletions pkg/workspace/workspace_export_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -194,3 +194,27 @@ func TestRootWorkspaceCatalogPath(t *testing.T) {
})
}
}

func TestListCatalogs(t *testing.T) {
rootPath := "test-workspace"
fsys := fstest.MapFS{
"test-workspace/.warpforge": &fstest.MapFile{Mode: 0644 | fs.ModeDir},
"test-workspace/.warpforge/root": &fstest.MapFile{Mode: 0644},
"test-workspace/.warpforge/catalogs": &fstest.MapFile{Mode: 0644 | fs.ModeDir},
"test-workspace/.warpforge/catalogs/somedir": &fstest.MapFile{Mode: 0644 | fs.ModeDir},
"test-workspace/.warpforge/catalogs/symlink": &fstest.MapFile{Mode: 0644 | fs.ModeSymlink},
"test-workspace/.warpforge/catalogs/just-a-file-counts": &fstest.MapFile{Mode: 0644},
"test-workspace/.warpforge/catalogs/_not_a_catalog": &fstest.MapFile{Mode: 0644 | fs.ModeDir},
"test-workspace/.warpforge/catalogs/1-still-a.catalog": &fstest.MapFile{Mode: 0644 | fs.ModeDir},
}
ws, err := workspace.OpenWorkspace(fsys, rootPath)
qt.Assert(t, err, qt.IsNil)
qt.Assert(t, ws.IsRootWorkspace(), qt.IsTrue)
qt.Assert(t, ws.IsHomeWorkspace(), qt.IsFalse)
result, err := ws.ListCatalogs()
qt.Check(t, err, qt.IsNil)
expected := []string{
"somedir", "symlink", "just-a-file-counts", "1-still-a.catalog",
}
qt.Check(t, result, qt.ContentEquals, expected)
}

0 comments on commit a9f4fce

Please sign in to comment.