package config import . "gopkg.in/check.v1" type ConfigSuite struct{} var _ = Suite(&ConfigSuite{}) 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"}, }, } c.Assert(config.Validate(), Equals, ErrRemoteConfigEmptyURL) } func (s *ConfigSuite) TestValidateInvalidKey(c *C) { config := &Config{ Remotes: map[string]*RemoteConfig{ "bar": {Name: "foo"}, }, } c.Assert(config.Validate(), Equals, ErrInvalid) } func (s *ConfigSuite) TestRemoteConfigValidateMissingURL(c *C) { config := &RemoteConfig{Name: "foo"} c.Assert(config.Validate(), Equals, ErrRemoteConfigEmptyURL) } func (s *ConfigSuite) TestRemoteConfigValidateMissingName(c *C) { config := &RemoteConfig{} c.Assert(config.Validate(), Equals, ErrRemoteConfigEmptyName) } func (s *ConfigSuite) TestRemoteConfigValidateDefault(c *C) { config := &RemoteConfig{Name: "foo", URL: "http://foo/bar"} c.Assert(config.Validate(), IsNil) fetch := config.Fetch c.Assert(fetch, HasLen, 1) c.Assert(fetch[0].String(), Equals, "+refs/heads/*:refs/remotes/foo/*") }