Skip to content

Commit

Permalink
Further test coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
barnybug committed Oct 19, 2015
1 parent 5aed53f commit 7428349
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 19 deletions.
3 changes: 2 additions & 1 deletion cmd/cli53/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@ import (
)

func main() {
cli53.Main(os.Args)
exitCode := cli53.Main(os.Args)
os.Exit(exitCode)
}
5 changes: 4 additions & 1 deletion cmd/cli53/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,8 @@ import (
// Test started when the test binary is started. Only calls main.
func TestSystem(t *testing.T) {
args := append([]string{"cli53"}, flag.Args()...)
cli53.Main(args)
exitCode := cli53.Main(args)
if exitCode != 0 {
t.Errorf("exit code: %d\n", exitCode)
}
}
16 changes: 10 additions & 6 deletions commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -250,9 +250,10 @@ type createArgs struct {
continentCode string
}

func (args createArgs) validate() {
func (args createArgs) validate() bool {
if args.failover != "" && args.failover != "PRIMARY" && args.failover != "SECONDARY" {
errorAndExit("failover must be PRIMARY or SECONDARY")
fmt.Println("failover must be PRIMARY or SECONDARY")
return false
}
extcount := 0
if args.failover != "" {
Expand All @@ -271,14 +272,18 @@ func (args createArgs) validate() {
extcount += 1
}
if extcount > 0 && args.identifier == "" {
errorAndExit("identifier must be set when creating an extended record")
fmt.Println("identifier must be set when creating an extended record")
return false
}
if extcount == 0 && args.identifier != "" {
errorAndExit("identifier should only be set when creating an extended record")
fmt.Println("identifier should only be set when creating an extended record")
return false
}
if extcount > 1 {
errorAndExit("failover, weight, region, country-code and continent-code are mutually exclusive")
fmt.Println("failover, weight, region, country-code and continent-code are mutually exclusive")
return false
}
return true
}

func equalStringPtrs(a, b *string) bool {
Expand All @@ -292,7 +297,6 @@ func equalStringPtrs(a, b *string) bool {
}

func createRecord(args createArgs) {
args.validate()
zone := lookupZone(args.name)

origin := fmt.Sprintf("$ORIGIN %s\n", *zone.Name)
Expand Down
28 changes: 28 additions & 0 deletions internal/features/validation.feature
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,31 @@ Feature: parameter validation
Scenario: failover and weight are mutually exclusive
When I execute "cli53 rrcreate -i id --failover PRIMARY --weight 10 $domain 'a A 127.0.0.1'"
Then the exit code was 1

Scenario: create requires one argument
When I execute "cli53 create a b"
Then the exit code was 1

Scenario: delete requires one argument
When I execute "cli53 delete a b"
Then the exit code was 1

Scenario: import requires one argument
When I execute "cli53 import a b"
Then the exit code was 1

Scenario: export requires one argument
When I execute "cli53 export a b"
Then the exit code was 1

Scenario: rrcreate requires two arguments
When I execute "cli53 import a b c"
Then the exit code was 1

Scenario: rrdelete requires three arguments
When I execute "cli53 import a b c d"
Then the exit code was 1

Scenario: rrpurge requires one argument
When I execute "cli53 rrpurge a b"
Then the exit code was 1
33 changes: 22 additions & 11 deletions main.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package cli53

import (
"os"

"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/service/route53"
"github.com/codegangsta/cli"
Expand All @@ -12,7 +10,8 @@ var r53 *route53.Route53
var version string /* passed in by go build */

// Entry point for cli53 application
func Main(args []string) {
func Main(args []string) int {
exitCode := 0
app := cli.NewApp()
app.Name = "cli53"
app.Usage = "manage route53 DNS"
Expand Down Expand Up @@ -46,7 +45,8 @@ func Main(args []string) {
r53 = getService(c.Bool("debug"))
if len(c.Args()) != 1 {
cli.ShowCommandHelp(c, "create")
os.Exit(1)
exitCode = 1
return
}
createZone(c.Args().First(), c.String("comment"))
},
Expand All @@ -69,7 +69,8 @@ func Main(args []string) {
r53 = getService(c.Bool("debug"))
if len(c.Args()) != 1 {
cli.ShowCommandHelp(c, "delete")
os.Exit(1)
exitCode = 1
return
}
domain := c.Args().First()
deleteZone(domain, c.Bool("purge"))
Expand Down Expand Up @@ -106,7 +107,8 @@ func Main(args []string) {
r53 = getService(c.Bool("debug"))
if len(c.Args()) != 1 {
cli.ShowCommandHelp(c, "import")
os.Exit(1)
exitCode = 1
return
}
importBind(c.Args().First(), c.String("file"), c.Bool("wait"), c.Bool("editauth"), c.Bool("replace"))
},
Expand All @@ -129,7 +131,8 @@ func Main(args []string) {
r53 = getService(c.Bool("debug"))
if len(c.Args()) != 1 {
cli.ShowCommandHelp(c, "export")
os.Exit(1)
exitCode = 1
return
}
exportBind(c.Args().First(), c.Bool("full"))
},
Expand Down Expand Up @@ -185,7 +188,8 @@ func Main(args []string) {
r53 = getService(c.Bool("debug"))
if len(c.Args()) != 2 {
cli.ShowCommandHelp(c, "rrcreate")
os.Exit(1)
exitCode = 1
return
}
var weight *int
if c.IsSet("weight") {
Expand All @@ -204,7 +208,11 @@ func Main(args []string) {
countryCode: c.String("country-code"),
continentCode: c.String("continent-code"),
}
createRecord(args)
if args.validate() {
createRecord(args)
} else {
exitCode = 1
}
},
},
{
Expand All @@ -230,7 +238,8 @@ func Main(args []string) {
r53 = getService(c.Bool("debug"))
if len(c.Args()) != 3 {
cli.ShowCommandHelp(c, "rrdelete")
os.Exit(1)
exitCode = 1
return
}
deleteRecord(c.Args()[0], c.Args()[1], c.Args()[2], c.Bool("wait"), c.String("identifier"))
},
Expand All @@ -257,7 +266,8 @@ func Main(args []string) {
r53 = getService(c.Bool("debug"))
if len(c.Args()) != 1 {
cli.ShowCommandHelp(c, "rrpurge")
os.Exit(1)
exitCode = 1
return
}
if !c.Bool("confirm") {
errorAndExit("You must --confirm this action")
Expand All @@ -267,4 +277,5 @@ func Main(args []string) {
},
}
app.Run(args)
return exitCode
}

0 comments on commit 7428349

Please sign in to comment.