Переглянути джерело

Add a test to ensure types are parsed correctly.

Nimi Wariboko 11 роки тому
батько
коміт
eead139b57
1 змінених файлів з 37 додано та 0 видалено
  1. 37 0
      marshal_test.go

+ 37 - 0
marshal_test.go

@@ -287,3 +287,40 @@ func (c *CustomString) UnmarshalCQL(info *TypeInfo, data []byte) error {
 type MyString string
 type MyString string
 
 
 type MyInt int
 type MyInt int
+
+var typeLookupTest = []struct {
+	TypeName     string
+	ExpectedType Type
+}{
+	{"AsciiType", TypeAscii},
+	{"LongType", TypeBigInt},
+	{"BytesType", TypeBlob},
+	{"BooleanType", TypeBoolean},
+	{"CounterColumnType", TypeCounter},
+	{"DecimalType", TypeDecimal},
+	{"DoubleType", TypeDouble},
+	{"FloatType", TypeFloat},
+	{"Int32Type", TypeInt},
+	{"DateType", TypeTimestamp},
+	{"UUIDType", TypeUUID},
+	{"UTF8Type", TypeVarchar},
+	{"IntegerType", TypeVarint},
+	{"TimeUUIDType", TypeTimeUUID},
+	{"InetAddressType", TypeInet},
+	{"MapType", TypeMap},
+	{"ListType", TypeInet},
+	{"SetType", TypeInet},
+	{"unknown", TypeCustom},
+}
+
+func testType(t *testing.T, cassType string, expectedType Type) {
+	if computedType := getApacheCassandraType(apacheCassandraTypePrefix + cassType); computedType != expectedType {
+		t.Errorf("Cassandra custom type lookup for %s failed. Expected %s, got %s.", cassType, expectedType.String(), computedType.String())
+	}
+}
+
+func TestLookupCassType(t *testing.T) {
+	for _, lookupTest := range typeLookupTest {
+		testType(t, lookupTest.TypeName, lookupTest.ExpectedType)
+	}
+}