Skip to content

Commit

Permalink
chore(gnomod): test package does not exist (#1317)
Browse files Browse the repository at this point in the history
Add test for package does not exist.

Not able to reproduce `Infinite loop when a requested package does not
exist` (#835)
  • Loading branch information
harry-hov authored Nov 8, 2023
1 parent 678686a commit 041d0a8
Showing 1 changed file with 42 additions and 18 deletions.
60 changes: 42 additions & 18 deletions gnovm/pkg/gnomod/file_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,30 @@ func TestFetchDeps(t *testing.T) {
for _, tc := range []struct {
desc string
modFile File
errorShouldContain string
requirements []string
stdOutContains []string
cachedStdOutContains []string
}{
{
desc: "not_exists",
modFile: File{
Module: &modfile.Module{
Mod: module.Version{
Path: "testFetchDeps",
},
},
Require: []*modfile.Require{
{
Mod: module.Version{
Path: "gno.land/p/demo/does_not_exists",
Version: "v0.0.0",
},
},
},
},
errorShouldContain: "querychain (gno.land/p/demo/does_not_exists)",
}, {
desc: "fetch_gno.land/p/demo/avl",
modFile: File{
Module: &modfile.Module{
Expand Down Expand Up @@ -89,29 +108,34 @@ func TestFetchDeps(t *testing.T) {
defer cleanUpFn()

// Fetching dependencies
tc.modFile.FetchDeps(dirPath, testRemote, true)
err := tc.modFile.FetchDeps(dirPath, testRemote, true)
if tc.errorShouldContain != "" {
require.ErrorContains(t, err, tc.errorShouldContain)
} else {
require.Nil(t, err)

// Read dir
entries, err := os.ReadDir(filepath.Join(dirPath, "gno.land", "p", "demo"))
require.Nil(t, err)
// Read dir
entries, err := os.ReadDir(filepath.Join(dirPath, "gno.land", "p", "demo"))
require.Nil(t, err)

// Check dir entries
assert.Equal(t, len(tc.requirements), len(entries))
for _, e := range entries {
assert.Contains(t, tc.requirements, e.Name())
}
// Check dir entries
assert.Equal(t, len(tc.requirements), len(entries))
for _, e := range entries {
assert.Contains(t, tc.requirements, e.Name())
}

// Check logs
for _, c := range tc.stdOutContains {
assert.Contains(t, buf.String(), c)
}
// Check logs
for _, c := range tc.stdOutContains {
assert.Contains(t, buf.String(), c)
}

buf.Reset()
buf.Reset()

// Try fetching again. Should be cached
tc.modFile.FetchDeps(dirPath, testRemote, true)
for _, c := range tc.cachedStdOutContains {
assert.Contains(t, buf.String(), c)
// Try fetching again. Should be cached
tc.modFile.FetchDeps(dirPath, testRemote, true)
for _, c := range tc.cachedStdOutContains {
assert.Contains(t, buf.String(), c)
}
}
})
}
Expand Down

0 comments on commit 041d0a8

Please sign in to comment.