Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

fixing some

  • Loading branch information...
commit a3cef7f10c4b8a3f8f95ef7cd55b2a0d01fb219e 1 parent 74e1750
@tebeka authored
Showing with 25 additions and 22 deletions.
  1. +6 −2 dw/dw.go
  2. +19 −20 dw/dw_test.go
View
8 dw/dw.go
@@ -17,7 +17,7 @@ const (
// Command line options
var direwolfHost = flag.String("direwolfHost", defaultHost, "direwolf host")
-var apiKey = flag.String("apiKey", os.Getenv("DW_API_KEY"), "api key to use (or DW_API_KEY)")
+var apiKey = flag.String("apiKey", "", "api key to use (or DW_API_KEY)")
var listClouds = flag.Bool("listClouds", false, "list clouds and exit")
var domain = flag.String("domain", "", "cloud domain")
var region = flag.String("region", "", "cloud region")
@@ -197,6 +197,9 @@ func main() {
flag.Parse()
if len(*apiKey) == 0 {
+ *apiKey = os.Getenv("DW_API_KEY")
+ }
+ if len(*apiKey) == 0 {
die("no api key")
}
@@ -234,7 +237,8 @@ func main() {
fmt.Printf("%s\n", status) // Print final status
duration := status.End.Sub(*status.Start).Seconds()
- fmt.Printf("run %s ended at %s (started at %s - took %.1fsec)\n", status.Id, *status.End, *status.Start, duration)
+ fmt.Printf("run %s ended at %s (started at %s - took %.1fsec)\n",
+ status.Id, *status.End, *status.Start, duration)
if status.Summary.Failed > 0 {
os.Exit(1)
}
View
39 dw/dw_test.go
@@ -95,17 +95,17 @@ func Test_getClouds(t *testing.T) {
t.Fatalf("no clouds found")
}
- found := false
- for _, cloud := range clouds {
- // FIXME: Use findCloudId
- if (cloud.Domain == testCloud) && (cloud.Region == "us") {
- found = true
- break
- }
+ id := findCloudId(testCloud, "us", clouds)
+ if id == "" {
+ t.Fatalf("can't find %s cloud", testCloud)
}
+}
- if !found {
- t.Fatalf("can't find %s cloud", testCloud)
+func checkFindId(cloud, region string, clouds []Cloud, expected bool, t *testing.T) {
+ t.Logf("Testing findCloudId %s:%s [%s]", cloud, region, expected)
+ found := len(findCloudId(cloud, region, clouds)) != 0
+ if found != expected {
+ t.Fatalf("error in %s:%s", cloud, region)
}
}
@@ -116,19 +116,18 @@ func test_findCloudId(t *testing.T) {
t.Fatalf("can't get clouds - %s", err)
}
- id := findCloudId(testCloud, "us", clouds)
- if len(id) == 0 {
- t.Fatalf("can't find cloud %s- %s", testCloud, err)
- }
-
- id = findCloudId(testCloud, "ussr", clouds)
- if len(id) != 0 {
- t.Fatalf("found cloud in bad region")
+ var cases = []struct {
+ cloud string
+ region string
+ expected bool
+ }{
+ {testCloud, "us", true},
+ {testCloud, "ussr", false},
+ {testCloud + "not-there", "us", false},
}
- id = findCloudId(testCloud+"no-there", "us", clouds)
- if len(id) != 0 {
- t.Fatalf("found non existing cloud")
+ for _, data := range cases {
+ checkFindId(data.cloud, data.region, clouds, data.expected, t)
}
}
Please sign in to comment.
Something went wrong with that request. Please try again.