github.com/datastax/go-cassandra-native-protocol@v0.0.0-20220706104457-5e8aad05cf90/datatype/primitive_test.go (about)

     1  // Copyright 2020 DataStax
     2  //
     3  // Licensed under the Apache License, Version 2.0 (the "License");
     4  // you may not use this file except in compliance with the License.
     5  // You may obtain a copy of the License at
     6  //
     7  //      http://www.apache.org/licenses/LICENSE-2.0
     8  //
     9  // Unless required by applicable law or agreed to in writing, software
    10  // distributed under the License is distributed on an "AS IS" BASIS,
    11  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  // See the License for the specific language governing permissions and
    13  // limitations under the License.
    14  
    15  package datatype
    16  
    17  import (
    18  	"testing"
    19  
    20  	"github.com/stretchr/testify/assert"
    21  
    22  	"github.com/datastax/go-cassandra-native-protocol/primitive"
    23  )
    24  
    25  func TestPrimitiveType(t *testing.T) {
    26  	tests := []struct {
    27  		name     string
    28  		input    *PrimitiveType
    29  		expected primitive.DataTypeCode
    30  	}{
    31  		{"Ascii", Ascii, primitive.DataTypeCodeAscii},
    32  		{"Bigint", Bigint, primitive.DataTypeCodeBigint},
    33  		{"Blob", Blob, primitive.DataTypeCodeBlob},
    34  		{"Boolean", Boolean, primitive.DataTypeCodeBoolean},
    35  		{"Counter", Counter, primitive.DataTypeCodeCounter},
    36  		{"Decimal", Decimal, primitive.DataTypeCodeDecimal},
    37  		{"Double", Double, primitive.DataTypeCodeDouble},
    38  		{"Float", Float, primitive.DataTypeCodeFloat},
    39  		{"Int", Int, primitive.DataTypeCodeInt},
    40  		{"Timestamp", Timestamp, primitive.DataTypeCodeTimestamp},
    41  		{"Uuid", Uuid, primitive.DataTypeCodeUuid},
    42  		{"Varchar", Varchar, primitive.DataTypeCodeVarchar},
    43  		{"Varint", Varint, primitive.DataTypeCodeVarint},
    44  		{"Timeuuid", Timeuuid, primitive.DataTypeCodeTimeuuid},
    45  		{"Inet", Inet, primitive.DataTypeCodeInet},
    46  		{"Date", Date, primitive.DataTypeCodeDate},
    47  		{"Time", Time, primitive.DataTypeCodeTime},
    48  		{"Smallint", Smallint, primitive.DataTypeCodeSmallint},
    49  		{"Tinyint", Tinyint, primitive.DataTypeCodeTinyint},
    50  		{"Duration", Duration, primitive.DataTypeCodeDuration},
    51  	}
    52  	for _, test := range tests {
    53  		t.Run(test.name, func(t *testing.T) {
    54  			actual := test.input.Code()
    55  			assert.Equal(t, test.expected, actual)
    56  		})
    57  	}
    58  }