From 0c0e31996a8c1e606ef8345535fbdabc5bec3fd9 Mon Sep 17 00:00:00 2001 From: Norman Meier Date: Sat, 30 Nov 2024 01:36:43 +0100 Subject: [PATCH] chore: improve pkgdownload doc and testing Signed-off-by: Norman Meier --- .../pkgdownload/examplespkgfetcher/examplespkgfetcher.go | 4 +++- .../gno/internal/pkgdownload/gnopkgfetcher/gnopkgfetcher.go | 2 ++ .../internal/pkgdownload/gnopkgfetcher/gnopkgfetcher_test.go | 5 ++--- gnovm/cmd/gno/internal/pkgdownload/pkgdownload.go | 3 +++ 4 files changed, 10 insertions(+), 4 deletions(-) diff --git a/gnovm/cmd/gno/internal/pkgdownload/examplespkgfetcher/examplespkgfetcher.go b/gnovm/cmd/gno/internal/pkgdownload/examplespkgfetcher/examplespkgfetcher.go index dba29cd8e83..9129d4758e2 100644 --- a/gnovm/cmd/gno/internal/pkgdownload/examplespkgfetcher/examplespkgfetcher.go +++ b/gnovm/cmd/gno/internal/pkgdownload/examplespkgfetcher/examplespkgfetcher.go @@ -1,3 +1,5 @@ +// Package gnopkgfetcher provides an implementation of [pkgdownload.PackageFetcher] +// to fetches packages from the examples folder at GNOROOT package examplespkgfetcher import ( @@ -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)) diff --git a/gnovm/cmd/gno/internal/pkgdownload/gnopkgfetcher/gnopkgfetcher.go b/gnovm/cmd/gno/internal/pkgdownload/gnopkgfetcher/gnopkgfetcher.go index 7481b5baf71..e0f866b2089 100644 --- a/gnovm/cmd/gno/internal/pkgdownload/gnopkgfetcher/gnopkgfetcher.go +++ b/gnovm/cmd/gno/internal/pkgdownload/gnopkgfetcher/gnopkgfetcher.go @@ -1,3 +1,5 @@ +// Package gnopkgfetcher provides an implementation of [pkgdownload.PackageFetcher] +// to fetches packages from tm2 rpc endpoints package gnopkgfetcher import ( diff --git a/gnovm/cmd/gno/internal/pkgdownload/gnopkgfetcher/gnopkgfetcher_test.go b/gnovm/cmd/gno/internal/pkgdownload/gnopkgfetcher/gnopkgfetcher_test.go index fac964147dc..0c295d0fc82 100644 --- a/gnovm/cmd/gno/internal/pkgdownload/gnopkgfetcher/gnopkgfetcher_test.go +++ b/gnovm/cmd/gno/internal/pkgdownload/gnopkgfetcher/gnopkgfetcher_test.go @@ -1,7 +1,6 @@ package gnopkgfetcher import ( - "fmt" "testing" "github.com/stretchr/testify/require" @@ -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"`, }, } @@ -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) diff --git a/gnovm/cmd/gno/internal/pkgdownload/pkgdownload.go b/gnovm/cmd/gno/internal/pkgdownload/pkgdownload.go index 39769f2c245..4d2861083e8 100644 --- a/gnovm/cmd/gno/internal/pkgdownload/pkgdownload.go +++ b/gnovm/cmd/gno/internal/pkgdownload/pkgdownload.go @@ -1,3 +1,4 @@ +// Package pkgdownload provides interfaces and utility functions to download gno packages files. package pkgdownload import ( @@ -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 {