|
14 | 14 | package modules_test |
15 | 15 |
|
16 | 16 | import ( |
| 17 | + "strings" |
17 | 18 | "testing" |
18 | 19 |
|
| 20 | + qt "github.com/frankban/quicktest" |
19 | 21 | "github.com/gohugoio/hugo/hugolib" |
20 | 22 | ) |
21 | 23 |
|
@@ -48,3 +50,49 @@ Deps: {{ range hugo.Deps}}{{ printf "%s@%s" .Path .Version }}|{{ end }}$ |
48 | 50 | b.AssertFileContent("public/blog/music/autumn-leaves/index.html", "Autumn Leaves is a popular jazz standard") // v0.2.0 |
49 | 51 | b.AssertFileContent("public/v1/blog/music/autumn-leaves/index.html", "Lorem markdownum, placidi peremptis") // v0.1.0 |
50 | 52 | } |
| 53 | + |
| 54 | +// Issue 14010 |
| 55 | +func TestModuleImportErrors(t *testing.T) { |
| 56 | + t.Parallel() |
| 57 | + |
| 58 | + files := ` |
| 59 | +-- hugo.toml -- |
| 60 | +[[module.imports]] |
| 61 | +PATH |
| 62 | +VERSION |
| 63 | +` |
| 64 | + f := strings.NewReplacer("PATH", "", "VERSION", "").Replace(files) |
| 65 | + b, err := hugolib.TestE(t, f) |
| 66 | + b.Assert(err, qt.IsNotNil) |
| 67 | + b.Assert(err, qt.ErrorMatches, `^failed to load modules: module "" not found.*`) |
| 68 | + |
| 69 | + f = strings.NewReplacer("PATH", "path = 'foo'", "VERSION", "").Replace(files) |
| 70 | + b, err = hugolib.TestE(t, f) |
| 71 | + b.Assert(err, qt.IsNotNil) |
| 72 | + b.Assert(err, qt.ErrorMatches, `^failed to load modules: module "foo" not found.*`) |
| 73 | + |
| 74 | + f = strings.NewReplacer("PATH", "path = 'foo'", "VERSION", "version = 'badSemVer'").Replace(files) |
| 75 | + b, err = hugolib.TestE(t, f) |
| 76 | + b.Assert(err, qt.IsNotNil) |
| 77 | + b.Assert(err, qt.ErrorMatches, `failed to load modules: malformed module path "foo": missing dot in first path element`) |
| 78 | + |
| 79 | + f = strings.NewReplacer("PATH", "path = 'foo.bar'", "VERSION", "version = 'badSemVer'").Replace(files) |
| 80 | + b, err = hugolib.TestE(t, f) |
| 81 | + b.Assert(err, qt.IsNotNil) |
| 82 | + b.Assert(err, qt.ErrorMatches, `failed to load modules: foo.bar@badSemVer: invalid version: not a semantic version`) |
| 83 | + |
| 84 | + f = strings.NewReplacer("PATH", "path = 'foo.bar'", "VERSION", "version = 'v6.7.42'").Replace(files) |
| 85 | + b, err = hugolib.TestE(t, f) |
| 86 | + b.Assert(err, qt.IsNotNil) |
| 87 | + b.Assert(err, qt.ErrorMatches, `failed to load modules: foo.bar@v6.7.42: invalid version: should be v0 or v1, not v6`) |
| 88 | + |
| 89 | + f = strings.NewReplacer("PATH", "path = 'foo.bar/v2'", "VERSION", "version = 'v6.7.42'").Replace(files) |
| 90 | + b, err = hugolib.TestE(t, f) |
| 91 | + b.Assert(err, qt.IsNotNil) |
| 92 | + b.Assert(err, qt.ErrorMatches, `failed to load modules: foo.bar/v2@v6.7.42: invalid version: should be v2, not v6`) |
| 93 | + |
| 94 | + f = strings.NewReplacer("PATH", "path = 'github.com/bep/hugo-mod-misc/dummy-content/v99'", "VERSION", "version = 'v99.0.0'").Replace(files) |
| 95 | + b, err = hugolib.TestE(t, f) |
| 96 | + b.Assert(err, qt.IsNotNil) |
| 97 | + b.Assert(err, qt.ErrorMatches, `failed to load modules: failed to download module github.com/bep/hugo-mod-misc/dummy-content/v99@v99.0.0: github.com/bep/hugo-mod-misc/dummy-content/v99@v99.0.0: invalid version: unknown revision dummy-content/v99.0.0`) |
| 98 | +} |
0 commit comments