diff options
author | Máximo Cuadros <mcuadros@gmail.com> | 2016-11-07 20:29:58 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-11-07 20:29:58 +0100 |
commit | 0ff9ef2b44c53e557c78bde0fd9c29847e5f0e23 (patch) | |
tree | b9c7485fe99e6e89fa736ceb0223aeb2ecddb77c /config | |
parent | f6ed7424cbf33c7013332d7e95b4262a4bc4a523 (diff) | |
download | go-git-0ff9ef2b44c53e557c78bde0fd9c29847e5f0e23.tar.gz |
global storage interface refactor (#112)
* core: ObjectStorage, ReferenceStorage renamed to ObjectStorer and
ReferenceStorer
* rebase
* general, changes request by @alcortes
* general, changes request by @alcortes
Diffstat (limited to 'config')
-rw-r--r-- | config/config.go | 39 | ||||
-rw-r--r-- | config/config_test.go | 20 |
2 files changed, 54 insertions, 5 deletions
diff --git a/config/config.go b/config/config.go index f94d4c9..b7482ea 100644 --- a/config/config.go +++ b/config/config.go @@ -7,22 +7,51 @@ import ( ) const ( + // DefaultRefSpec is the default refspec used, when none is given DefaultRefSpec = "+refs/heads/*:refs/remotes/%s/*" ) +// ConfigStorer interface to persist Config objects +type ConfigStorer interface { + Config() (*Config, error) + SetConfig(*Config) error +} + var ( + ErrInvalid = errors.New("config invalid remote") ErrRemoteConfigNotFound = errors.New("remote config not found") ErrRemoteConfigEmptyURL = errors.New("remote config: empty URL") ErrRemoteConfigEmptyName = errors.New("remote config: empty name") ) -type ConfigStorage interface { - Remote(name string) (*RemoteConfig, error) - Remotes() ([]*RemoteConfig, error) - SetRemote(*RemoteConfig) error - DeleteRemote(name string) error +// Config contains the repository configuration +type Config struct { + Remotes map[string]*RemoteConfig +} + +// NewConfig returns a new empty Config +func NewConfig() *Config { + return &Config{ + Remotes: make(map[string]*RemoteConfig, 0), + } +} + +// Validate validate the fields and set the default values +func (c *Config) Validate() error { + for name, r := range c.Remotes { + if r.Name != name { + return ErrInvalid + } + + if err := r.Validate(); err != nil { + return err + } + } + + return nil } +// RemoteConfig contains the configuration for a given repository type RemoteConfig struct { Name string URL string diff --git a/config/config_test.go b/config/config_test.go index d97053b..f2539d0 100644 --- a/config/config_test.go +++ b/config/config_test.go @@ -6,6 +6,26 @@ type ConfigSuite struct{} var _ = Suite(&ConfigSuite{}) +func (s *ConfigSuite) TestConfigValidateInvalidRemote(c *C) { + config := &Config{ + Remotes: map[string]*RemoteConfig{ + "foo": {Name: "foo"}, + }, + } + + c.Assert(config.Validate(), Equals, ErrRemoteConfigEmptyURL) +} + +func (s *ConfigSuite) TestConfigValidateInvalidKey(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) |