-
Notifications
You must be signed in to change notification settings - Fork 379
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Norman Meier <[email protected]>
- Loading branch information
Showing
1 changed file
with
54 additions
and
0 deletions.
There are no files selected for viewing
54 changes: 54 additions & 0 deletions
54
gnovm/cmd/gno/internal/pkgdownload/gnopkgfetcher/gnopkgfetcher_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package gnopkgfetcher | ||
|
||
import ( | ||
"fmt" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestRpcURLFromPkgPath(t *testing.T) { | ||
cases := []struct { | ||
name string | ||
pkgPath string | ||
overrides map[string]string | ||
result string | ||
errorContains string | ||
}{ | ||
{ | ||
name: "happy path simple", | ||
pkgPath: "gno.land/p/demo/avl", | ||
result: "https://rpc.gno.land:443", | ||
}, | ||
{ | ||
name: "happy path override", | ||
pkgPath: "gno.land/p/demo/avl", | ||
overrides: map[string]string{"gno.land": "https://example.com/rpc:42"}, | ||
result: "https://example.com/rpc:42", | ||
}, | ||
{ | ||
name: "happy path override no effect", | ||
pkgPath: "gno.land/p/demo/avl", | ||
overrides: map[string]string{"some.chain": "https://example.com/rpc:42"}, | ||
result: "https://rpc.gno.land:443", | ||
}, | ||
{ | ||
name: "error bad pkg path", | ||
pkgPath: "std", | ||
result: "", | ||
errorContains: fmt.Sprintf("bad pkg path %q", "std"), | ||
}, | ||
} | ||
|
||
for _, c := range cases { | ||
t.Run(c.name, func(t *testing.T) { | ||
res, err := rpcURLFromPkgPath(c.pkgPath, c.overrides) | ||
if len(c.errorContains) == 0 { | ||
require.NoError(t, err) | ||
} else if err != nil { | ||
require.ErrorContains(t, err, c.errorContains) | ||
} | ||
require.Equal(t, c.result, res) | ||
}) | ||
} | ||
} |