-
-
Notifications
You must be signed in to change notification settings - Fork 7.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
modules: Add noVendor to module config
Fixes #7647
- Loading branch information
Showing
6 changed files
with
118 additions
and
56 deletions.
There are no files selected for viewing
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
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
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
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
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 |
---|---|---|
|
@@ -19,8 +19,6 @@ import ( | |
|
||
"github.com/gohugoio/hugo/hugofs/glob" | ||
|
||
"github.com/gohugoio/hugo/common/hugo" | ||
|
||
"github.com/gohugoio/hugo/htesting" | ||
|
||
"github.com/gohugoio/hugo/hugofs" | ||
|
@@ -29,77 +27,109 @@ import ( | |
) | ||
|
||
func TestClient(t *testing.T) { | ||
if hugo.GoMinorVersion() < 12 { | ||
// https://github.com/golang/go/issues/26794 | ||
// There were some concurrent issues with Go modules in < Go 12. | ||
t.Skip("skip this for Go <= 1.11 due to a bug in Go's stdlib") | ||
} | ||
|
||
t.Parallel() | ||
|
||
modName := "hugo-modules-basic-test" | ||
modPath := "github.com/gohugoio/tests/" + modName | ||
modConfig := DefaultModuleConfig | ||
modConfig.Imports = []Import{Import{Path: "github.com/gohugoio/hugoTestModules1_darwin/modh2_2"}} | ||
expect := `github.com/gohugoio/tests/hugo-modules-basic-test github.com/gohugoio/hugoTestModules1_darwin/[email protected] | ||
github.com/gohugoio/hugoTestModules1_darwin/[email protected] github.com/gohugoio/hugoTestModules1_darwin/[email protected] | ||
github.com/gohugoio/hugoTestModules1_darwin/[email protected] github.com/gohugoio/hugoTestModules1_darwin/[email protected] | ||
` | ||
|
||
c := qt.New(t) | ||
|
||
workingDir, clean, err := htesting.CreateTempDir(hugofs.Os, modName) | ||
c.Assert(err, qt.IsNil) | ||
defer clean() | ||
newClient := func(c *qt.C, withConfig func(cfg *ClientConfig)) (*Client, func()) { | ||
|
||
client := NewClient(ClientConfig{ | ||
Fs: hugofs.Os, | ||
WorkingDir: workingDir, | ||
ModuleConfig: modConfig, | ||
}) | ||
workingDir, clean, err := htesting.CreateTempDir(hugofs.Os, modName) | ||
c.Assert(err, qt.IsNil) | ||
|
||
ccfg := ClientConfig{ | ||
Fs: hugofs.Os, | ||
WorkingDir: workingDir, | ||
} | ||
|
||
// Test Init | ||
c.Assert(client.Init(modPath), qt.IsNil) | ||
withConfig(&ccfg) | ||
ccfg.ModuleConfig.Imports = []Import{Import{Path: "github.com/gohugoio/hugoTestModules1_darwin/modh2_2"}} | ||
client := NewClient(ccfg) | ||
|
||
// Test Collect | ||
mc, err := client.Collect() | ||
c.Assert(err, qt.IsNil) | ||
c.Assert(len(mc.AllModules), qt.Equals, 4) | ||
for _, m := range mc.AllModules { | ||
c.Assert(m, qt.Not(qt.IsNil)) | ||
return client, clean | ||
} | ||
|
||
// Test Graph | ||
var graphb bytes.Buffer | ||
c.Assert(client.Graph(&graphb), qt.IsNil) | ||
c.Run("All", func(c *qt.C) { | ||
client, clean := newClient(c, func(cfg *ClientConfig) { | ||
cfg.ModuleConfig = DefaultModuleConfig | ||
}) | ||
defer clean() | ||
|
||
expect := `github.com/gohugoio/tests/hugo-modules-basic-test github.com/gohugoio/hugoTestModules1_darwin/[email protected] | ||
github.com/gohugoio/hugoTestModules1_darwin/[email protected] github.com/gohugoio/hugoTestModules1_darwin/[email protected] | ||
github.com/gohugoio/hugoTestModules1_darwin/[email protected] github.com/gohugoio/hugoTestModules1_darwin/[email protected] | ||
` | ||
// Test Init | ||
c.Assert(client.Init(modPath), qt.IsNil) | ||
|
||
// Test Collect | ||
mc, err := client.Collect() | ||
c.Assert(err, qt.IsNil) | ||
c.Assert(len(mc.AllModules), qt.Equals, 4) | ||
for _, m := range mc.AllModules { | ||
c.Assert(m, qt.Not(qt.IsNil)) | ||
} | ||
|
||
// Test Graph | ||
var graphb bytes.Buffer | ||
c.Assert(client.Graph(&graphb), qt.IsNil) | ||
|
||
c.Assert(graphb.String(), qt.Equals, expect) | ||
|
||
c.Assert(graphb.String(), qt.Equals, expect) | ||
// Test Vendor | ||
c.Assert(client.Vendor(), qt.IsNil) | ||
graphb.Reset() | ||
c.Assert(client.Graph(&graphb), qt.IsNil) | ||
|
||
// Test Vendor | ||
c.Assert(client.Vendor(), qt.IsNil) | ||
graphb.Reset() | ||
c.Assert(client.Graph(&graphb), qt.IsNil) | ||
expectVendored := `project github.com/gohugoio/hugoTestModules1_darwin/[email protected]+vendor | ||
expectVendored := `project github.com/gohugoio/hugoTestModules1_darwin/[email protected]+vendor | ||
project github.com/gohugoio/hugoTestModules1_darwin/[email protected]+vendor | ||
project github.com/gohugoio/hugoTestModules1_darwin/[email protected]+vendor | ||
` | ||
c.Assert(graphb.String(), qt.Equals, expectVendored) | ||
|
||
// Test the ignoreVendor setting | ||
clientIgnoreVendor := NewClient(ClientConfig{ | ||
Fs: hugofs.Os, | ||
WorkingDir: workingDir, | ||
ModuleConfig: modConfig, | ||
IgnoreVendor: globAll, | ||
|
||
c.Assert(graphb.String(), qt.Equals, expectVendored) | ||
|
||
// Test Tidy | ||
c.Assert(client.Tidy(), qt.IsNil) | ||
|
||
}) | ||
|
||
graphb.Reset() | ||
c.Assert(clientIgnoreVendor.Graph(&graphb), qt.IsNil) | ||
c.Assert(graphb.String(), qt.Equals, expect) | ||
c.Run("IgnoreVendor", func(c *qt.C) { | ||
client, clean := newClient( | ||
c, func(cfg *ClientConfig) { | ||
cfg.ModuleConfig = DefaultModuleConfig | ||
cfg.IgnoreVendor = globAll | ||
}) | ||
defer clean() | ||
|
||
c.Assert(client.Init(modPath), qt.IsNil) | ||
_, err := client.Collect() | ||
c.Assert(err, qt.IsNil) | ||
c.Assert(client.Vendor(), qt.IsNil) | ||
|
||
var graphb bytes.Buffer | ||
c.Assert(client.Graph(&graphb), qt.IsNil) | ||
c.Assert(graphb.String(), qt.Equals, expect) | ||
}) | ||
|
||
// Test Tidy | ||
c.Assert(client.Tidy(), qt.IsNil) | ||
c.Run("NoVendor", func(c *qt.C) { | ||
mcfg := DefaultModuleConfig | ||
mcfg.NoVendor = "**" | ||
client, clean := newClient( | ||
c, func(cfg *ClientConfig) { | ||
cfg.ModuleConfig = mcfg | ||
}) | ||
defer clean() | ||
|
||
c.Assert(client.Init(modPath), qt.IsNil) | ||
_, err := client.Collect() | ||
c.Assert(err, qt.IsNil) | ||
c.Assert(client.Vendor(), qt.IsNil) | ||
|
||
var graphb bytes.Buffer | ||
c.Assert(client.Graph(&graphb), qt.IsNil) | ||
c.Assert(graphb.String(), qt.Equals, expect) | ||
}) | ||
|
||
} | ||
|
||
|
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