Skip to content

Commit

Permalink
Support fallback conf
Browse files Browse the repository at this point in the history
  • Loading branch information
crispgm committed Apr 9, 2019
1 parent d3d6b0f commit 9f7e16a
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 3 deletions.
10 changes: 8 additions & 2 deletions caravan/conf.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,14 @@ func LoadFrom(path, spec string) (*Conf, error) {
if err != nil {
return nil, err
}
if spec, ok := conf[spec]; ok {
return &spec, nil
if specConf, ok := conf[spec]; ok {
return &specConf, nil
}
if spec == DefaultSpec && len(conf) == 1 {
for specName, specConf := range conf {
PrintNotice("No spec name specified, choose", specName, "instead")
return &specConf, nil
}
}
return nil, errors.New("No spec")
}
Expand Down
9 changes: 9 additions & 0 deletions caravan/conf_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,15 @@ func TestLoadConf(t *testing.T) {
assert.Error(t, err)
}

func TestLoadFallbackConf(t *testing.T) {
var err error
spec, err := LoadFrom("../fixtures/caravan_fallback.yml", "master")
assert.NoError(t, err)
assert.Equal(t, "/path/to/fallback", spec.Source)
_, err = LoadFrom("../fixtures/caravan_fallback_error.yml", "master")
assert.Error(t, err)
}

func TestCreateDefault(t *testing.T) {
err := CreateDefault("../fixtures/testoutput/caravan.yml")
assert.NoError(t, err)
Expand Down
9 changes: 9 additions & 0 deletions fixtures/caravan_fallback.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
fallback:
src: /path/to/fallback
dst: /Users/david/dev/test/to
debug: false
deploy_mode: rsync
incremental: true
exclude:
- .git
once: false
18 changes: 18 additions & 0 deletions fixtures/caravan_fallback_error.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
fallback:
src: /path/to/fallback
dst: /Users/david/dev/test/to
debug: false
deploy_mode: rsync
incremental: true
exclude:
- .git
once: false
fallbackerror:
src: /path/to/fallback
dst: /Users/david/dev/test/to
debug: false
deploy_mode: rsync
incremental: true
exclude:
- .git
once: false
2 changes: 1 addition & 1 deletion process.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"github.com/crispgm/go-van/deploy"
)

const goVanVersion = "2.1.1"
const goVanVersion = "2.2.0"

var (
errFileExisted = errors.New("Conf file existed")
Expand Down

0 comments on commit 9f7e16a

Please sign in to comment.