feat(pkg): honor search limit after cache
All checks were successful
Security Scan / security (push) Successful in 14s
All checks were successful
Security Scan / security (push) Successful in 14s
Co-Authored-By: Virgil <virgil@lethean.io>
This commit is contained in:
parent
d50b006af9
commit
04d244425b
2 changed files with 46 additions and 0 deletions
|
|
@ -11,6 +11,7 @@ import (
|
|||
"testing"
|
||||
"time"
|
||||
|
||||
"forge.lthn.ai/core/go-cache"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
|
@ -248,3 +249,44 @@ func TestRenderPkgSearchResults_ShowsMetadata(t *testing.T) {
|
|||
assert.Contains(t, out, "Go")
|
||||
assert.Contains(t, out, "updated 2h ago")
|
||||
}
|
||||
|
||||
func TestRunPkgSearch_RespectsLimitWithCachedResults(t *testing.T) {
|
||||
tmp := t.TempDir()
|
||||
writeTestRegistry(t, tmp)
|
||||
withWorkingDir(t, tmp)
|
||||
|
||||
c, err := cache.New(nil, filepath.Join(tmp, ".core", "cache"), 0)
|
||||
require.NoError(t, err)
|
||||
require.NoError(t, c.Set(cache.GitHubReposKey("host-uk"), []ghRepo{
|
||||
{
|
||||
FullName: "host-uk/core-alpha",
|
||||
Name: "core-alpha",
|
||||
Description: "Alpha package",
|
||||
Visibility: "public",
|
||||
UpdatedAt: time.Now().Add(-time.Hour).Format(time.RFC3339),
|
||||
StargazerCount: 1,
|
||||
PrimaryLanguage: ghLanguage{
|
||||
Name: "Go",
|
||||
},
|
||||
},
|
||||
{
|
||||
FullName: "host-uk/core-beta",
|
||||
Name: "core-beta",
|
||||
Description: "Beta package",
|
||||
Visibility: "public",
|
||||
UpdatedAt: time.Now().Add(-2 * time.Hour).Format(time.RFC3339),
|
||||
StargazerCount: 2,
|
||||
PrimaryLanguage: ghLanguage{
|
||||
Name: "Go",
|
||||
},
|
||||
},
|
||||
}))
|
||||
|
||||
out := capturePkgOutput(t, func() {
|
||||
err := runPkgSearch("host-uk", "*", "", 1, false, "table")
|
||||
require.NoError(t, err)
|
||||
})
|
||||
|
||||
assert.Contains(t, out, "core-alpha")
|
||||
assert.NotContains(t, out, "core-beta")
|
||||
}
|
||||
|
|
|
|||
|
|
@ -188,6 +188,10 @@ func runPkgSearch(org, pattern, repoType string, limit int, refresh bool, format
|
|||
return cmp.Compare(a.Name, b.Name)
|
||||
})
|
||||
|
||||
if limit > 0 && len(filtered) > limit {
|
||||
filtered = filtered[:limit]
|
||||
}
|
||||
|
||||
if strings.EqualFold(format, "json") {
|
||||
report := buildPkgSearchReport(org, pattern, repoType, limit, fromCache, filtered)
|
||||
return printPkgSearchJSON(report)
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue