forked from apache/cassandra-gocql-driver
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
metadata: fix all types being NativeType (apache#1052)
Parse the correct TypeInfo from the cassandra string in the db. Fixing representation to recursivly parse the nested types.
- Loading branch information
Showing
4 changed files
with
145 additions
and
23 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
package gocql | ||
|
||
import ( | ||
"reflect" | ||
"testing" | ||
) | ||
|
||
func TestGetCassandraType_Set(t *testing.T) { | ||
typ := getCassandraType("set<text>") | ||
set, ok := typ.(CollectionType) | ||
if !ok { | ||
t.Fatalf("expected CollectionType got %T", typ) | ||
} else if set.typ != TypeSet { | ||
t.Fatalf("expected type %v got %v", TypeSet, set.typ) | ||
} | ||
|
||
inner, ok := set.Elem.(NativeType) | ||
if !ok { | ||
t.Fatalf("expected to get NativeType got %T", set.Elem) | ||
} else if inner.typ != TypeText { | ||
t.Fatalf("expected to get %v got %v for set value", TypeText, set.typ) | ||
} | ||
} | ||
|
||
func TestGetCassandraType(t *testing.T) { | ||
tests := []struct { | ||
input string | ||
exp TypeInfo | ||
}{ | ||
{ | ||
"set<text>", CollectionType{ | ||
NativeType: NativeType{typ: TypeSet}, | ||
|
||
Elem: NativeType{typ: TypeText}, | ||
}, | ||
}, | ||
{ | ||
"map<text, varchar>", CollectionType{ | ||
NativeType: NativeType{typ: TypeMap}, | ||
|
||
Key: NativeType{typ: TypeText}, | ||
Elem: NativeType{typ: TypeVarchar}, | ||
}, | ||
}, | ||
{ | ||
"list<int>", CollectionType{ | ||
NativeType: NativeType{typ: TypeList}, | ||
Elem: NativeType{typ: TypeInt}, | ||
}, | ||
}, | ||
{ | ||
"tuple<int, int, text>", TupleTypeInfo{ | ||
NativeType: NativeType{typ: TypeTuple}, | ||
|
||
Elems: []TypeInfo{ | ||
NativeType{typ: TypeInt}, | ||
NativeType{typ: TypeInt}, | ||
NativeType{typ: TypeText}, | ||
}, | ||
}, | ||
}, | ||
} | ||
|
||
for _, test := range tests { | ||
t.Run(test.input, func(t *testing.T) { | ||
got := getCassandraType(test.input) | ||
|
||
// TODO(zariel): define an equal method on the types? | ||
if !reflect.DeepEqual(got, test.exp) { | ||
t.Fatalf("expected %v got %v", test.exp, got) | ||
} | ||
}) | ||
} | ||
} |
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