Skip to content

Commit

Permalink
Added checks on table names in case changes change them
Browse files Browse the repository at this point in the history
  • Loading branch information
John W committed Apr 26, 2016
1 parent c65a96f commit 047d56b
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 1 deletion.
1 change: 1 addition & 0 deletions multimap_multikey_table_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ var (
func TestMultimapMultiKeyTableInsertRead(t *testing.T) {
tbl := ns.MultimapMultiKeyTable(tablename+"90", StorePK, StoreIndex, Store{})
createIf(tbl.(TableChanger), t)
validateTableName(t, tbl.(TableChanger), "store90_multimapMk")
london := Store{
City: "London",
Manager: "Joe",
Expand Down
1 change: 1 addition & 0 deletions multimap_table_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ type Customer2 struct {
func TestMultimapTableInsertRead(t *testing.T) {
tbl := ns.MultimapTable("customer91", "Tag", "Id", Customer2{})
createIf(tbl.(TableChanger), t)
validateTableName(t, tbl.(TableChanger), "customer91_multimap_Tag_Id")
joe := Customer2{
Id: "33",
Name: "Joe",
Expand Down
1 change: 1 addition & 0 deletions multitimeseries_table_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ type TripB struct {
func TestMultiTimeSeriesTable(t *testing.T) {
tbl := ns.MultiTimeSeriesTable("tripTime6", "Tag", "Time", "Id", time.Minute, TripB{})
createIf(tbl.(TableChanger), t)
validateTableName(t, tbl.(TableChanger), "tripTime6_multiTimeSeries_Tag_Time_Id_1m0s")
err := tbl.WithOptions(Options{TTL: 30 * time.Second}).Set(TripB{
Id: "1",
Time: parse("2006 Jan 2 15:03:59"),
Expand Down
14 changes: 13 additions & 1 deletion table_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,13 @@ func TestTables(t *testing.T) {

func TestCreateTable(t *testing.T) {
rand.Seed(time.Now().Unix())
name := fmt.Sprintf("customer_%v", rand.Int()%100)
randy := rand.Int()%100
name := fmt.Sprintf("customer_%v", randy)
cs := ns.Table(name, Customer{}, Keys{
PartitionKeys: []string{"Id", "Name"},
})
createIf(cs, t)
validateTableName(t, cs.(TableChanger), fmt.Sprintf("customer_%d__Id_Name__", randy))
err := cs.Set(Customer{
Id: "1001",
Name: "Joe",
Expand Down Expand Up @@ -64,6 +66,7 @@ func TestClusteringOrder(t *testing.T) {
ClusteringColumns: []string{"Id"},
}).WithOptions(options)
createIf(cs, t)
validateTableName(t, cs.(TableChanger), "customer_by_name__Name__Id")

customers := []Customer{
Customer{
Expand Down Expand Up @@ -175,6 +178,7 @@ func TestCreateStatement(t *testing.T) {
PartitionKeys: []string{"Id", "Name"},
})
str, err := cs.CreateStatement()
validateTableName(t, cs.(TableChanger), "something__Id_Name__")
if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -346,3 +350,11 @@ func TestExecuteWithConsistency(t *testing.T) {
t.Fatal(fmt.Sprint("Expected consistency:", cons, "got:", resultOpts.Consistency))
}
}

func validateTableName(t *testing.T, tbl TableChanger, expected string) bool {
ok := tbl.Name() == expected
if !ok {
t.Fatalf("Table name should be: %s and NOT: %s", expected, tbl.Name())
}
return ok
}

0 comments on commit 047d56b

Please sign in to comment.