-
Notifications
You must be signed in to change notification settings - Fork 59
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
increase code coverage substantially (#11)
* added tests around client * use an interface for client for testability reasons * added coverage
- Loading branch information
Showing
33 changed files
with
1,223 additions
and
221 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,8 +15,188 @@ | |
//Package db is where the Astra DB commands are | ||
package db | ||
|
||
import "testing" | ||
import ( | ||
"fmt" | ||
"testing" | ||
|
||
func TestCreate(t *testing.T) { | ||
t.Skip("ignore") | ||
"github.com/rsds143/astra-cli/pkg" | ||
tests "github.com/rsds143/astra-cli/pkg/tests" | ||
"github.com/rsds143/astra-devops-sdk-go/astraops" | ||
) | ||
|
||
func TestCreateGetsId(t *testing.T) { | ||
expectedID := "abcd" | ||
//setting package variables by hand, there be dragons | ||
mockClient := &tests.MockClient{ | ||
Databases: []astraops.Database{ | ||
{ | ||
ID: expectedID, | ||
}, | ||
}, | ||
} | ||
err := executeCreate(func() (pkg.Client, error) { | ||
return mockClient, nil | ||
}) | ||
if err != nil { | ||
t.Fatalf("unexpected error '%v'", err) | ||
} | ||
|
||
if len(mockClient.Calls()) != 1 { | ||
t.Fatalf("expected 1 call but was %v", len(mockClient.Calls())) | ||
} | ||
} | ||
func TestCreateLoginFails(t *testing.T) { | ||
//setting package variables by hand, there be dragons | ||
mockClient := &tests.MockClient{} | ||
err := executeCreate(func() (pkg.Client, error) { | ||
return mockClient, fmt.Errorf("service down") | ||
}) | ||
if err == nil { | ||
t.Fatal("expected error") | ||
} | ||
|
||
expected := "unable to login with error service down" | ||
if err.Error() != expected { | ||
t.Errorf("expected '%v' but was '%v'", expected, err.Error()) | ||
} | ||
if len(mockClient.Calls()) != 0 { | ||
t.Fatalf("expected 0 call but was %v", len(mockClient.Calls())) | ||
} | ||
} | ||
|
||
func TestCreateFails(t *testing.T) { | ||
//setting package variables by hand, there be dragons | ||
mockClient := &tests.MockClient{ | ||
ErrorQueue: []error{fmt.Errorf("service down")}, | ||
} | ||
err := executeCreate(func() (pkg.Client, error) { | ||
return mockClient, nil | ||
}) | ||
if err == nil { | ||
t.Fatal("expected error") | ||
} | ||
|
||
if len(mockClient.Calls()) != 1 { | ||
t.Fatalf("expected 1 call but was %v", len(mockClient.Calls())) | ||
} | ||
} | ||
|
||
func TestCreateSetsName(t *testing.T) { | ||
mockClient := &tests.MockClient{} | ||
createDbName = "mydb" | ||
err := executeCreate(func() (pkg.Client, error) { | ||
return mockClient, nil | ||
}) | ||
if err != nil { | ||
t.Fatalf("unexpected error '%v'", err) | ||
} | ||
arg0 := mockClient.Call(0).(astraops.CreateDb) | ||
if arg0.Name != createDbName { | ||
t.Errorf("expected '%v' but was '%v'", arg0.Name, createDbName) | ||
} | ||
} | ||
|
||
func TestCreateSetsKeyspace(t *testing.T) { | ||
mockClient := &tests.MockClient{} | ||
createDbKeyspace = "myKeyspace" | ||
err := executeCreate(func() (pkg.Client, error) { | ||
return mockClient, nil | ||
}) | ||
if err != nil { | ||
t.Fatalf("unexpected error '%v'", err) | ||
} | ||
arg0 := mockClient.Call(0).(astraops.CreateDb) | ||
if arg0.Keyspace != createDbKeyspace { | ||
t.Errorf("expected '%v' but was '%v'", arg0.Keyspace, createDbKeyspace) | ||
} | ||
} | ||
|
||
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.CreateDb) | ||
if arg0.CapacityUnits != int32(createDbCapacityUnit) { | ||
t.Errorf("expected '%v' but was '%v'", arg0.CapacityUnits, createDbCapacityUnit) | ||
} | ||
} | ||
|
||
func TestCreateSetsRegion(t *testing.T) { | ||
mockClient := &tests.MockClient{} | ||
createDbRegion = "EU-West1" | ||
err := executeCreate(func() (pkg.Client, error) { | ||
return mockClient, nil | ||
}) | ||
if err != nil { | ||
t.Fatalf("unexpected error '%v'", err) | ||
} | ||
arg0 := mockClient.Call(0).(astraops.CreateDb) | ||
if arg0.Region != createDbRegion { | ||
t.Errorf("expected '%v' but was '%v'", arg0.Region, createDbRegion) | ||
} | ||
} | ||
|
||
func TestCreateSetsUser(t *testing.T) { | ||
mockClient := &tests.MockClient{} | ||
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.CreateDb) | ||
if arg0.User != createDbUser { | ||
t.Errorf("expected '%v' but was '%v'", arg0.User, createDbUser) | ||
} | ||
} | ||
|
||
func TestCreateSetsPass(t *testing.T) { | ||
mockClient := &tests.MockClient{} | ||
createDbUser = "afdfdf" | ||
err := executeCreate(func() (pkg.Client, error) { | ||
return mockClient, nil | ||
}) | ||
if err != nil { | ||
t.Fatalf("unexpected error '%v'", err) | ||
} | ||
arg0 := mockClient.Call(0).(astraops.CreateDb) | ||
if arg0.Password != createDbPassword { | ||
t.Errorf("expected '%v' but was '%v'", arg0.Password, createDbPassword) | ||
} | ||
} | ||
|
||
func TestCreateSetsTier(t *testing.T) { | ||
mockClient := &tests.MockClient{} | ||
createDbTier = "afdfdf" | ||
err := executeCreate(func() (pkg.Client, error) { | ||
return mockClient, nil | ||
}) | ||
if err != nil { | ||
t.Fatalf("unexpected error '%v'", err) | ||
} | ||
arg0 := mockClient.Call(0).(astraops.CreateDb) | ||
if arg0.Tier != createDbTier { | ||
t.Errorf("expected '%v' but was '%v'", arg0.Tier, createDbTier) | ||
} | ||
} | ||
|
||
func TestCreateSetsProvider(t *testing.T) { | ||
mockClient := &tests.MockClient{} | ||
createDbCloudProvider = "ryanscloud" | ||
err := executeCreate(func() (pkg.Client, error) { | ||
return mockClient, nil | ||
}) | ||
if err != nil { | ||
t.Fatalf("unexpected error '%v'", err) | ||
} | ||
arg0 := mockClient.Call(0).(astraops.CreateDb) | ||
if arg0.CloudProvider != createDbCloudProvider { | ||
t.Errorf("expected '%v' but was '%v'", arg0.CloudProvider, createDbCloudProvider) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.