From b0a32a786e740d314bfc3d3ae76a698a81c39eb9 Mon Sep 17 00:00:00 2001 From: Máximo Cuadros Date: Thu, 26 Jan 2017 14:31:46 +0100 Subject: config: git modules config --- config/modules.go | 43 +++++++++++++++++++++++++++++++++++++++++++ config/modules_test.go | 23 +++++++++++++++++++++++ 2 files changed, 66 insertions(+) create mode 100644 config/modules.go create mode 100644 config/modules_test.go diff --git a/config/modules.go b/config/modules.go new file mode 100644 index 0000000..3f095fa --- /dev/null +++ b/config/modules.go @@ -0,0 +1,43 @@ +package config + +import "errors" + +var ( + ErrModuleEmptyURL = errors.New("module config: empty URL") + ErrModuleEmptyPath = errors.New("module config: empty path") +) + +const DefaultModuleBranch = "master" + +// Modules defines the submodules properties +type Modules map[string]*Module + +// Module defines a submodule +// https://www.kernel.org/pub/software/scm/git/docs/gitmodules.html +type Module struct { + // Path defines the path, relative to the top-level directory of the Git + // working tree, + Path string + // URL defines a URL from which the submodule repository can be cloned. + URL string + // Branch is a remote branch name for tracking updates in the upstream + // submodule. + Branch string +} + +// Validate validate the fields and set the default values +func (m *Module) Validate() error { + if m.Path == "" { + return ErrModuleEmptyPath + } + + if m.URL == "" { + return ErrModuleEmptyURL + } + + if m.Branch == "" { + m.Branch = DefaultModuleBranch + } + + return nil +} diff --git a/config/modules_test.go b/config/modules_test.go new file mode 100644 index 0000000..50b5691 --- /dev/null +++ b/config/modules_test.go @@ -0,0 +1,23 @@ +package config + +import . "gopkg.in/check.v1" + +type ModuleSuite struct{} + +var _ = Suite(&ModuleSuite{}) + +func (s *ModuleSuite) TestModuleValidateMissingURL(c *C) { + m := &Module{Path: "foo"} + c.Assert(m.Validate(), Equals, ErrModuleEmptyURL) +} + +func (s *ModuleSuite) TestModuleValidateMissingName(c *C) { + m := &Module{URL: "bar"} + c.Assert(m.Validate(), Equals, ErrModuleEmptyPath) +} + +func (s *ModuleSuite) TestModuleValidateDefault(c *C) { + m := &Module{Path: "foo", URL: "http://foo/bar"} + c.Assert(m.Validate(), IsNil) + c.Assert(m.Branch, Equals, DefaultModuleBranch) +} -- cgit