aboutsummaryrefslogtreecommitdiffstats
path: root/config/modules_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'config/modules_test.go')
-rw-r--r--config/modules_test.go70
1 files changed, 60 insertions, 10 deletions
diff --git a/config/modules_test.go b/config/modules_test.go
index 50b5691..34ad17c 100644
--- a/config/modules_test.go
+++ b/config/modules_test.go
@@ -2,22 +2,72 @@ package config
import . "gopkg.in/check.v1"
-type ModuleSuite struct{}
+type ModulesSuite struct{}
-var _ = Suite(&ModuleSuite{})
+var _ = Suite(&ModulesSuite{})
-func (s *ModuleSuite) TestModuleValidateMissingURL(c *C) {
- m := &Module{Path: "foo"}
+func (s *ModulesSuite) TestValidateMissingURL(c *C) {
+ m := &Submodule{Path: "foo"}
c.Assert(m.Validate(), Equals, ErrModuleEmptyURL)
}
-func (s *ModuleSuite) TestModuleValidateMissingName(c *C) {
- m := &Module{URL: "bar"}
+func (s *ModulesSuite) TestValidateMissingName(c *C) {
+ m := &Submodule{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)
+func (s *ModulesSuite) TestMarshall(c *C) {
+ input := []byte(`[submodule "qux"]
+ path = qux
+ url = baz
+ branch = bar
+`)
+
+ cfg := NewModules()
+ cfg.Submodules["qux"] = &Submodule{Path: "qux", URL: "baz", Branch: "bar"}
+
+ output, err := cfg.Marshal()
+ c.Assert(err, IsNil)
+ c.Assert(output, DeepEquals, input)
+}
+
+func (s *ModulesSuite) TestUnmarshall(c *C) {
+ input := []byte(`[submodule "qux"]
+ path = qux
+ url = https://github.com/foo/qux.git
+[submodule "foo/bar"]
+ path = foo/bar
+ url = https://github.com/foo/bar.git
+ branch = dev
+`)
+
+ cfg := NewModules()
+ err := cfg.Unmarshal(input)
+ c.Assert(err, IsNil)
+
+ c.Assert(cfg.Submodules, HasLen, 2)
+ c.Assert(cfg.Submodules["qux"].Name, Equals, "qux")
+ c.Assert(cfg.Submodules["qux"].URL, Equals, "https://github.com/foo/qux.git")
+ c.Assert(cfg.Submodules["foo/bar"].Name, Equals, "foo/bar")
+ c.Assert(cfg.Submodules["foo/bar"].URL, Equals, "https://github.com/foo/bar.git")
+ c.Assert(cfg.Submodules["foo/bar"].Branch, Equals, "dev")
+}
+
+func (s *ModulesSuite) TestUnmarshallMarshall(c *C) {
+ input := []byte(`[submodule "qux"]
+ path = qux
+ url = https://github.com/foo/qux.git
+[submodule "foo/bar"]
+ path = foo/bar
+ url = https://github.com/foo/bar.git
+ ignore = all
+`)
+
+ cfg := NewModules()
+ err := cfg.Unmarshal(input)
+ c.Assert(err, IsNil)
+
+ output, err := cfg.Marshal()
+ c.Assert(err, IsNil)
+ c.Assert(output, DeepEquals, input)
}