aboutsummaryrefslogtreecommitdiffstats
path: root/config/modules_test.go
diff options
context:
space:
mode:
authorMáximo Cuadros <mcuadros@gmail.com>2017-01-30 11:56:32 +0100
committerGitHub <noreply@github.com>2017-01-30 11:56:32 +0100
commit9b058a30ea07dc237e3cc2ad434b3a6f51be340c (patch)
tree3e4f96e30bb4db396fb609d61913c6a6397577ad /config/modules_test.go
parent1c2602a791371e76d52f89b2c8193cb200c66ad6 (diff)
parent7581d7f76a08869ed1ad1384dea1880c635af58b (diff)
downloadgo-git-9b058a30ea07dc237e3cc2ad434b3a6f51be340c.tar.gz
Merge pull request #227 from mcuadros/submodules
config: marshal and unmarshal done inside of the package, and submodules config file
Diffstat (limited to 'config/modules_test.go')
-rw-r--r--config/modules_test.go73
1 files changed, 73 insertions, 0 deletions
diff --git a/config/modules_test.go b/config/modules_test.go
new file mode 100644
index 0000000..ab7b116
--- /dev/null
+++ b/config/modules_test.go
@@ -0,0 +1,73 @@
+package config
+
+import . "gopkg.in/check.v1"
+
+type ModulesSuite struct{}
+
+var _ = Suite(&ModulesSuite{})
+
+func (s *ModulesSuite) TestValidateMissingURL(c *C) {
+ m := &Submodule{Path: "foo"}
+ c.Assert(m.Validate(), Equals, ErrModuleEmptyURL)
+}
+
+func (s *ModulesSuite) TestValidateMissingName(c *C) {
+ m := &Submodule{URL: "bar"}
+ c.Assert(m.Validate(), Equals, ErrModuleEmptyPath)
+}
+
+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(string(output), DeepEquals, string(input))
+}