Skip to content

Commit

Permalink
error text from astra is displayed again, terminate will wait on fail…
Browse files Browse the repository at this point in the history
…ed terminates
  • Loading branch information
Ryan SVIHLA committed Feb 14, 2022
1 parent aae1080 commit 1ff6e14
Show file tree
Hide file tree
Showing 9 changed files with 81 additions and 162 deletions.
10 changes: 1 addition & 9 deletions cmd/db/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,21 +26,15 @@ import (

var createDbName string
var createDbKeyspace string
var createDbUser string
var createDbPassword string
var createDbRegion string
var createDbTier string
var createDbCapacityUnit int
var createDbCloudProvider string

func init() {
CreateCmd.Flags().StringVarP(&createDbName, "name", "n", "", "name to give to the Astra Database")
CreateCmd.Flags().StringVarP(&createDbKeyspace, "keyspace", "k", "", "keyspace user to give to the Astra Database")
CreateCmd.Flags().StringVarP(&createDbUser, "user", "u", "", "user password to give to the Astra Database")
CreateCmd.Flags().StringVarP(&createDbPassword, "password", "p", "", "db password to give to the Astra Database")
CreateCmd.Flags().StringVarP(&createDbRegion, "region", "r", "us-east1", "region to give to the Astra Database")
CreateCmd.Flags().StringVarP(&createDbTier, "tier", "t", "serverless", "tier to give to the Astra Database")
CreateCmd.Flags().IntVarP(&createDbCapacityUnit, "capacityUnit", "c", 1, "capacityUnit flag to give to the Astra Database")
CreateCmd.Flags().StringVarP(&createDbCloudProvider, "cloudProvider", "l", "GCP", "cloud provider flag to give to the Astra Database")
}

Expand All @@ -67,10 +61,8 @@ func executeCreate(makeClient func() (pkg.Client, error)) error {
createDb := astraops.DatabaseInfoCreate{
Name: createDbName,
Keyspace: createDbKeyspace,
CapacityUnits: createDbCapacityUnit,
CapacityUnits: 1, // we only support 1 CU on initial creation as of Feb 14 2022
Region: createDbRegion,
User: &createDbUser,
Password: &createDbPassword,
Tier: astraops.Tier(createDbTier),
CloudProvider: astraops.CloudProvider(createDbCloudProvider),
}
Expand Down
48 changes: 0 additions & 48 deletions cmd/db/create_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,21 +111,6 @@ func TestCreateSetsKeyspace(t *testing.T) {
}
}

func TestCreateSetsCapacityUnit(t *testing.T) {
mockClient := &tests.MockClient{}
createDbCapacityUnit = 10000
err := executeCreate(func() (pkg.Client, error) {
return mockClient, nil
})
if err != nil {
t.Fatalf("unexpected error '%v'", err)
}
arg0 := mockClient.Call(0).(astraops.DatabaseInfoCreate)
if arg0.CapacityUnits != createDbCapacityUnit {
t.Errorf("expected '%v' but was '%v'", arg0.CapacityUnits, createDbCapacityUnit)
}
}

func TestCreateSetsRegion(t *testing.T) {
mockClient := &tests.MockClient{}
createDbRegion = "EU-West1"
Expand All @@ -141,39 +126,6 @@ func TestCreateSetsRegion(t *testing.T) {
}
}

func TestCreateSetsUser(t *testing.T) {
mockClient := &tests.MockClient{}
// sets createDbUser on the package variable in cmd/db/create.go
createDbUser = "[email protected]"
err := executeCreate(func() (pkg.Client, error) {
return mockClient, nil
})
if err != nil {
t.Fatalf("unexpected error '%v'", err)
}
arg0 := mockClient.Call(0).(astraops.DatabaseInfoCreate)
if arg0.User != &createDbUser {
user := *arg0.User
t.Errorf("expected '%v' but was '%v'", user, createDbUser)
}
}

func TestCreateSetsPass(t *testing.T) {
mockClient := &tests.MockClient{}
// sets createDbPassword on the package variable in cmd/db/create.go
createDbPassword = "afdfdf"
err := executeCreate(func() (pkg.Client, error) {
return mockClient, nil
})
if err != nil {
t.Fatalf("unexpected error '%v'", err)
}
arg0 := mockClient.Call(0).(astraops.DatabaseInfoCreate)
if arg0.Password != &createDbPassword {
t.Errorf("expected '%v' but was '%v'", *arg0.Password, createDbPassword)
}
}

func TestCreateSetsTier(t *testing.T) {
mockClient := &tests.MockClient{}
createDbTier = "afdfdf"
Expand Down
2 changes: 1 addition & 1 deletion cmd/db/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ func executeList(login func() (pkg.Client, error)) (string, error) {
return "", fmt.Errorf("unable to login with error '%v'", err)
}
var dbs []astraops.Database
if dbs, err = client.ListDb(include, provider, startingAfter, int32(limit)); err != nil {
if dbs, err = client.ListDb(include, provider, startingAfter, limit); err != nil {
return "", fmt.Errorf("unable to get list of dbs with error '%v'", err)
}
switch listFmt {
Expand Down
2 changes: 1 addition & 1 deletion cmd/db/resize.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ func executeResize(args []string, makeClient func() (pkg.Client, error)) error {
Err: fmt.Errorf("unable to parse capacity unit '%s' with error %v", capacityUnitRaw, err),
}
}
if err := client.Resize(id, int32(capacityUnit)); err != nil {
if err := client.Resize(id, int(capacityUnit)); err != nil {
return fmt.Errorf("unable to resize '%s' with error %v", id, err)
}
fmt.Printf("resize database %v submitted with size %v\n", id, capacityUnit)
Expand Down
4 changes: 2 additions & 2 deletions cmd/db/resize_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ func TestResize(t *testing.T) {
if id != actualID {
t.Errorf("expected '%v' but was '%v'", id, actualID)
}
actualSize := mockClient.Call(0).([]interface{})[1].(int32)
if int32(100) != actualSize {
actualSize := mockClient.Call(0).([]interface{})[1].(int)
if 100 != actualSize {
t.Errorf("expected '%v' but was '%v'", size, actualSize)
}
}
Expand Down
Loading

0 comments on commit 1ff6e14

Please sign in to comment.