mirror of
https://github.com/gohugoio/hugo.git
synced 2024-11-29 02:42:08 -05:00
parent
08a863e1e8
commit
f122771fb1
2 changed files with 39 additions and 1 deletions
|
@ -11,6 +11,7 @@
|
||||||
// See the License for the specific language governing permissions and
|
// See the License for the specific language governing permissions and
|
||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
|
|
||||||
|
//go:build !nodeploy
|
||||||
// +build !nodeploy
|
// +build !nodeploy
|
||||||
|
|
||||||
package deploy
|
package deploy
|
||||||
|
@ -24,6 +25,7 @@ import (
|
||||||
hglob "github.com/gohugoio/hugo/hugofs/glob"
|
hglob "github.com/gohugoio/hugo/hugofs/glob"
|
||||||
"github.com/gohugoio/hugo/media"
|
"github.com/gohugoio/hugo/media"
|
||||||
"github.com/mitchellh/mapstructure"
|
"github.com/mitchellh/mapstructure"
|
||||||
|
"github.com/pkg/errors"
|
||||||
)
|
)
|
||||||
|
|
||||||
const deploymentConfigKey = "deployment"
|
const deploymentConfigKey = "deployment"
|
||||||
|
@ -124,12 +126,18 @@ func decodeConfig(cfg config.Provider) (deployConfig, error) {
|
||||||
return dcfg, err
|
return dcfg, err
|
||||||
}
|
}
|
||||||
for _, tgt := range dcfg.Targets {
|
for _, tgt := range dcfg.Targets {
|
||||||
|
if tgt == nil {
|
||||||
|
return dcfg, errors.New("empty deployment target")
|
||||||
|
}
|
||||||
if err := tgt.parseIncludeExclude(); err != nil {
|
if err := tgt.parseIncludeExclude(); err != nil {
|
||||||
return dcfg, err
|
return dcfg, err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
var err error
|
var err error
|
||||||
for _, m := range dcfg.Matchers {
|
for _, m := range dcfg.Matchers {
|
||||||
|
if m == nil {
|
||||||
|
return dcfg, errors.New("empty deployment matcher")
|
||||||
|
}
|
||||||
m.re, err = regexp.Compile(m.Pattern)
|
m.re, err = regexp.Compile(m.Pattern)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return dcfg, fmt.Errorf("invalid deployment.matchers.pattern: %v", err)
|
return dcfg, fmt.Errorf("invalid deployment.matchers.pattern: %v", err)
|
||||||
|
|
|
@ -11,6 +11,7 @@
|
||||||
// See the License for the specific language governing permissions and
|
// See the License for the specific language governing permissions and
|
||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
|
|
||||||
|
//go:build !nodeploy
|
||||||
// +build !nodeploy
|
// +build !nodeploy
|
||||||
|
|
||||||
package deploy
|
package deploy
|
||||||
|
@ -21,7 +22,6 @@ import (
|
||||||
|
|
||||||
qt "github.com/frankban/quicktest"
|
qt "github.com/frankban/quicktest"
|
||||||
"github.com/gohugoio/hugo/config"
|
"github.com/gohugoio/hugo/config"
|
||||||
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestDecodeConfigFromTOML(t *testing.T) {
|
func TestDecodeConfigFromTOML(t *testing.T) {
|
||||||
|
@ -169,3 +169,33 @@ func TestDecodeConfigDefault(t *testing.T) {
|
||||||
c.Assert(len(dcfg.Targets), qt.Equals, 0)
|
c.Assert(len(dcfg.Targets), qt.Equals, 0)
|
||||||
c.Assert(len(dcfg.Matchers), qt.Equals, 0)
|
c.Assert(len(dcfg.Matchers), qt.Equals, 0)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestEmptyTarget(t *testing.T) {
|
||||||
|
c := qt.New(t)
|
||||||
|
|
||||||
|
tomlConfig := `
|
||||||
|
[deployment]
|
||||||
|
[[deployment.targets]]
|
||||||
|
`
|
||||||
|
cfg, err := config.FromConfigString(tomlConfig, "toml")
|
||||||
|
c.Assert(err, qt.IsNil)
|
||||||
|
|
||||||
|
_, err = decodeConfig(cfg)
|
||||||
|
c.Assert(err, qt.Not(qt.IsNil))
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestEmptyMatcher(t *testing.T) {
|
||||||
|
c := qt.New(t)
|
||||||
|
|
||||||
|
tomlConfig := `
|
||||||
|
[deployment]
|
||||||
|
[[deployment.matchers]]
|
||||||
|
`
|
||||||
|
cfg, err := config.FromConfigString(tomlConfig, "toml")
|
||||||
|
c.Assert(err, qt.IsNil)
|
||||||
|
|
||||||
|
_, err = decodeConfig(cfg)
|
||||||
|
c.Assert(err, qt.Not(qt.IsNil))
|
||||||
|
|
||||||
|
fmt.Printf("JMM-1: %s", err)
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue