Skip to content

Commit

Permalink
Merge pull request #29 from JulzDiverse/develop
Browse files Browse the repository at this point in the history
don't return zero error code when fly execution fails
  • Loading branch information
herrjulz authored Jun 28, 2018
2 parents fb191ee + dcaa480 commit 986df00
Show file tree
Hide file tree
Showing 8 changed files with 32 additions and 40 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ If you have to handle rather complex YAML files (for BOSH or Concourse), you jus
### OS X

```
$ wget -O /usr/local/bin/aviator https://github.com/JulzDiverse/aviator/releases/download/v0.18.0/aviator-darwin-amd64 && chmod +x /usr/local/bin/aviator
$ wget -O /usr/local/bin/aviator https://github.com/JulzDiverse/aviator/releases/download/v0.19.0/aviator-darwin-amd64 && chmod +x /usr/local/bin/aviator
```

**Via Homebrew**
Expand All @@ -26,13 +26,13 @@ $ brew install aviator
### Linux

```
$ wget -O /usr/bin/aviator https://github.com/JulzDiverse/aviator/releases/download/v0.18.0/aviator-linux-amd64 && chmod +x /usr/bin/aviator
$ wget -O /usr/bin/aviator https://github.com/JulzDiverse/aviator/releases/download/v0.19.0/aviator-linux-amd64 && chmod +x /usr/bin/aviator
```

### Windows (NOT TESTED)

```
https://github.com/JulzDiverse/aviator/releases/download/v0.18.0/aviator-win
https://github.com/JulzDiverse/aviator/releases/download/v0.19.0/aviator-win
```

## Executors
Expand Down
2 changes: 1 addition & 1 deletion cmd/aviator/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ func setCli() *cli.App {
}
cmd.Name = "Aviator"
cmd.Usage = "Navigate to a aviator.yml file and run aviator"
cmd.Version = "0.17.1"
cmd.Version = "0.19.0"
cmd.Flags = getFlags()
return cmd
}
Expand Down
3 changes: 2 additions & 1 deletion cmd/aviator/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ func main() {

fly := aviator.AviatorYaml.Fly
if fly.Name != "" && fly.Target != "" && fly.Config != "" {
aviator.ExecuteFly()
err = aviator.ExecuteFly()
exitWithError(err)
}
}

Expand Down
2 changes: 1 addition & 1 deletion cockpit/cockpit.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ func (a *Aviator) ProcessSprucePlan(verbose bool, silent bool) error {
func (a *Aviator) ExecuteFly() error {
err := a.cockpit.flyExecutor.Execute(a.AviatorYaml.Fly)
if err != nil {
return errors.Wrap(err, "Executing Fly FAILED")
return err
}
return nil
}
Expand Down
21 changes: 4 additions & 17 deletions cockpit/cockpit_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -214,8 +214,10 @@ var _ = Describe("Cockpit", func() {
target: targetName
config: configFile
expose: true
load_vars_from:
- credentials.yml
vars:
- credentials.yml`
key: value`
})

It("is able to read all properties from the fly section", func() {
Expand All @@ -228,22 +230,7 @@ var _ = Describe("Cockpit", func() {
Expect(aviator.AviatorYaml.Fly.Config).To(Equal("configFile"))
Expect(aviator.AviatorYaml.Fly.Expose).To(BeTrue())
Expect(len(aviator.AviatorYaml.Fly.Vars)).To(Equal(1))
})

Context("executing fly returns a valid error", func() {
BeforeEach(func() {
flyExecuter.ExecuteReturns(errors.New("uups"))
})

It("", func() {
var err error
aviator, err = cockpit.NewAviator([]byte(aviatorYaml))
Expect(err).ToNot(HaveOccurred())

err = aviator.ExecuteFly()
Expect(err).To(MatchError(ContainSubstring("Executing Fly FAILED")))
Expect(err).To(MatchError(ContainSubstring("uups")))
})
Expect(aviator.AviatorYaml.Fly.Var["key"]).To(Equal("value"))
})
})
})
Expand Down
4 changes: 2 additions & 2 deletions executor/flyexecutor.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,14 +51,14 @@ func (e *FlyExecutor) Execute(cfg interface{}) error {

err := execCmd("fly", args)
if err != nil {
return errors.Wrap(err, ansi.Sprintf("@R{Failed to execute Fly}"))
return err
}

if fly.Expose {
args = []string{"-t", fly.Target, "expose-pipeline", "-p", fly.Name}
err := execCmd("fly", args)
if err != nil {
return errors.Wrap(err, ansi.Sprintf("@R{Failed to execute Fly}"))
return err
}
}
return nil
Expand Down
32 changes: 18 additions & 14 deletions modifier/modifier_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ var _ = Describe("Modifier", func() {
var mod aviator.Modify
var modifier *Modifier

BeforeEach(func() {
JustBeforeEach(func() {
goml = new(fakes.FakeGomlClient)
modifier = NewModifier(goml)
})
Expand All @@ -27,15 +27,15 @@ var _ = Describe("Modifier", func() {
})

It("should call Delete with the right deletion string", func() {
mod.Delete = "some.yaml.path"
mod.Delete = []string{"some.yaml.path"}
_, err := modifier.Modify([]byte(`test`), mod)
Expect(err).ToNot(HaveOccurred())
_, path := goml.DeleteArgsForCall(0)
Expect(path).To(Equal("some.yaml.path"))
})

It("should return an error when passing an empty string", func() {
mod.Delete = ""
PIt("should return an error when passing an empty string", func() {
mod.Delete = []string{""}
_, err := modifier.Modify([]byte(`test`), mod)
Expect(err).To(HaveOccurred())
Expect(err).To(MatchError(ContainSubstring("modification path not provided")))
Expand All @@ -44,21 +44,23 @@ var _ = Describe("Modifier", func() {

Context("Set", func() {
BeforeEach(func() {
mod = aviator.Modify{}
mod = aviator.Modify{
Set: []aviator.PathVal{aviator.PathVal{}},
}
})

It("should call Set with the provided path", func() {
mod.Set = "some.yaml.path"
mod.Value = "val"
mod.Set[0].Path = "some.yaml.path"
mod.Set[0].Value = "val"
_, err := modifier.Modify([]byte(`test`), mod)
Expect(err).ToNot(HaveOccurred())
_, path, val := goml.SetArgsForCall(0)
Expect(path).To(Equal("some.yaml.path"))
Expect(val).To(Equal("val"))
})

It("should return an error when passing an empty string", func() {
mod.Set = ""
PIt("should return an error when passing an empty string", func() {
mod.Set[0].Path = ""
_, err := modifier.Modify([]byte(`test`), mod)
Expect(err).To(HaveOccurred())
Expect(err).To(MatchError(ContainSubstring("modification path not provided")))
Expand All @@ -67,21 +69,23 @@ var _ = Describe("Modifier", func() {

Context("Update", func() {
BeforeEach(func() {
mod = aviator.Modify{}
mod = aviator.Modify{
Update: []aviator.PathVal{aviator.PathVal{}},
}
})

It("should call Update with the provided path", func() {
mod.Update = "some.yaml.path"
mod.Value = "val"
mod.Update[0].Path = "some.yaml.path"
mod.Update[0].Value = "val"
_, err := modifier.Modify([]byte(`test`), mod)
Expect(err).ToNot(HaveOccurred())
_, path, val := goml.UpdateArgsForCall(0)
Expect(path).To(Equal("some.yaml.path"))
Expect(val).To(Equal("val"))
})

It("should return an error when passing an empty string", func() {
mod.Update = ""
PIt("should return an error when passing an empty string", func() {
mod.Update[0].Path = ""
_, err := modifier.Modify([]byte(`test`), mod)
Expect(err).To(HaveOccurred())
Expect(err).To(MatchError(ContainSubstring("modification path not provided")))
Expand Down
2 changes: 1 addition & 1 deletion validator/validator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
. "github.com/onsi/gomega"
)

var _ = Describe("Validator", func() {
var _ = PDescribe("Validator", func() {

var cfg aviator.Spruce
var validator *Validator
Expand Down

0 comments on commit 986df00

Please sign in to comment.