aboutsummaryrefslogtreecommitdiffstats
path: root/config/config_test.go
diff options
context:
space:
mode:
authorMáximo Cuadros <mcuadros@gmail.com>2017-01-26 20:53:32 +0100
committerMáximo Cuadros <mcuadros@gmail.com>2017-01-26 20:53:32 +0100
commite2e4e7f748b4accf18950e0731248ed4ace63869 (patch)
tree970e55aa9083632bb402b2957393587b4a0e127c /config/config_test.go
parentb0a32a786e740d314bfc3d3ae76a698a81c39eb9 (diff)
downloadgo-git-e2e4e7f748b4accf18950e0731248ed4ace63869.tar.gz
config: marshal and unmarshal implementation
Diffstat (limited to 'config/config_test.go')
-rw-r--r--config/config_test.go48
1 files changed, 46 insertions, 2 deletions
diff --git a/config/config_test.go b/config/config_test.go
index f2539d0..2bcefe4 100644
--- a/config/config_test.go
+++ b/config/config_test.go
@@ -6,7 +6,51 @@ type ConfigSuite struct{}
var _ = Suite(&ConfigSuite{})
-func (s *ConfigSuite) TestConfigValidateInvalidRemote(c *C) {
+func (s *ConfigSuite) TestUnmarshall(c *C) {
+ input := []byte(`[core]
+ bare = true
+[remote "origin"]
+ url = git@github.com:mcuadros/go-git.git
+ fetch = +refs/heads/*:refs/remotes/origin/*
+[branch "master"]
+ remote = origin
+ merge = refs/heads/master
+`)
+
+ cfg := NewConfig()
+ err := cfg.Unmarshal(input)
+ c.Assert(err, IsNil)
+
+ c.Assert(cfg.Core.IsBare, Equals, true)
+ c.Assert(cfg.Remotes, HasLen, 1)
+ c.Assert(cfg.Remotes["origin"].Name, Equals, "origin")
+ c.Assert(cfg.Remotes["origin"].URL, Equals, "git@github.com:mcuadros/go-git.git")
+ c.Assert(cfg.Remotes["origin"].Fetch, DeepEquals, []RefSpec{"+refs/heads/*:refs/remotes/origin/*"})
+}
+
+func (s *ConfigSuite) TestUnmarshallMarshall(c *C) {
+ input := []byte(`[core]
+ bare = true
+ custom = ignored
+[remote "origin"]
+ url = git@github.com:mcuadros/go-git.git
+ fetch = +refs/heads/*:refs/remotes/origin/*
+ mirror = true
+[branch "master"]
+ remote = origin
+ merge = refs/heads/master
+`)
+
+ cfg := NewConfig()
+ err := cfg.Unmarshal(input)
+ c.Assert(err, IsNil)
+
+ output, err := cfg.Marshal()
+ c.Assert(err, IsNil)
+ c.Assert(output, DeepEquals, input)
+}
+
+func (s *ConfigSuite) TestValidateInvalidRemote(c *C) {
config := &Config{
Remotes: map[string]*RemoteConfig{
"foo": {Name: "foo"},
@@ -16,7 +60,7 @@ func (s *ConfigSuite) TestConfigValidateInvalidRemote(c *C) {
c.Assert(config.Validate(), Equals, ErrRemoteConfigEmptyURL)
}
-func (s *ConfigSuite) TestConfigValidateInvalidKey(c *C) {
+func (s *ConfigSuite) TestValidateInvalidKey(c *C) {
config := &Config{
Remotes: map[string]*RemoteConfig{
"bar": {Name: "foo"},