Skip to content

Commit

Permalink
chore: improve pkgdownload doc and testing
Browse files Browse the repository at this point in the history
Signed-off-by: Norman Meier <[email protected]>
  • Loading branch information
n0izn0iz committed Nov 30, 2024
1 parent 5ff7644 commit 0c0e319
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// Package gnopkgfetcher provides an implementation of [pkgdownload.PackageFetcher]
// to fetches packages from the examples folder at GNOROOT
package examplespkgfetcher

import (
Expand All @@ -17,7 +19,7 @@ func New() pkgdownload.PackageFetcher {
return &ExamplesPackageFetcher{}
}

// FetchPackage implements [pkgdownloadiface.PackageFetcher].
// FetchPackage implements [pkgdownload.PackageFetcher].
func (e *ExamplesPackageFetcher) FetchPackage(pkgPath string) ([]pkgdownload.PackageFile, error) {
pkgDir := filepath.Join(gnoenv.RootDir(), "examples", filepath.FromSlash(pkgPath))

Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// Package gnopkgfetcher provides an implementation of [pkgdownload.PackageFetcher]
// to fetches packages from tm2 rpc endpoints
package gnopkgfetcher

import (
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package gnopkgfetcher

import (
"fmt"
"testing"

"github.com/stretchr/testify/require"
Expand Down Expand Up @@ -36,7 +35,7 @@ func TestRpcURLFromPkgPath(t *testing.T) {
name: "error bad pkg path",
pkgPath: "std",
result: "",
errorContains: fmt.Sprintf("bad pkg path %q", "std"),
errorContains: `bad pkg path "std"`,
},
}

Expand All @@ -45,7 +44,7 @@ func TestRpcURLFromPkgPath(t *testing.T) {
res, err := rpcURLFromPkgPath(c.pkgPath, c.overrides)
if len(c.errorContains) == 0 {
require.NoError(t, err)
} else if err != nil {
} else {
require.ErrorContains(t, err, c.errorContains)
}
require.Equal(t, c.result, res)
Expand Down
3 changes: 3 additions & 0 deletions gnovm/cmd/gno/internal/pkgdownload/pkgdownload.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// Package pkgdownload provides interfaces and utility functions to download gno packages files.
package pkgdownload

import (
Expand All @@ -6,6 +7,8 @@ import (
"path/filepath"
)

// Download downloads the package identified by `pkgPath` in the directory at `dst` using the provided [PackageFetcher].
// The directory at `dst` is created if it does not exists.
func Download(pkgPath string, dst string, fetcher PackageFetcher) error {
files, err := fetcher.FetchPackage(pkgPath)
if err != nil {
Expand Down

0 comments on commit 0c0e319

Please sign in to comment.