Skip to content

Commit

Permalink
UT & IT
Browse files Browse the repository at this point in the history
  • Loading branch information
HTHou committed Sep 27, 2024
1 parent 6ced9d8 commit 7128a5f
Show file tree
Hide file tree
Showing 7 changed files with 333 additions and 34 deletions.
10 changes: 6 additions & 4 deletions client/field.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@

package client

import "time"

type Field struct {
dataType TSDataType
name string
Expand Down Expand Up @@ -89,10 +91,10 @@ func (f *Field) GetText() string {
return float64ToString(f.value.(float64))
case string:
return f.value.(string)
case []byte:
return bytesToHexString(f.value.([]byte))
case time.Time:
return f.value.(time.Time).Format(time.DateOnly)

Check failure on line 97 in client/field.go

View workflow job for this annotation

GitHub Actions / Build (ubuntu-latest, 1.13)

undefined: time.DateOnly
}
return ""
}

func (f *Field) GetBlob() []byte {
return f.value.([]byte)
}
89 changes: 89 additions & 0 deletions client/field_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ package client
import (
"reflect"
"testing"
"time"
)

func TestField_IsNull(t *testing.T) {
Expand Down Expand Up @@ -126,6 +127,38 @@ func TestField_GetDataType(t *testing.T) {
value: nil,
},
want: TEXT,
}, {
name: "GetDataType-STRING",
fields: fields{
dataType: STRING,
name: "",
value: nil,
},
want: STRING,
}, {
name: "GetDataType-BLOB",
fields: fields{
dataType: BLOB,
name: "",
value: nil,
},
want: BLOB,
}, {
name: "GetDataType-TIMESTAMP",
fields: fields{
dataType: TIMESTAMP,
name: "",
value: nil,
},
want: TIMESTAMP,
}, {
name: "GetDataType-DATE",
fields: fields{
dataType: DATE,
name: "",
value: nil,
},
want: DATE,
},
}
for _, tt := range tests {
Expand Down Expand Up @@ -201,6 +234,38 @@ func TestField_GetValue(t *testing.T) {
value: "TEXT",
},
want: "TEXT",
}, {
name: "GetValue-STRING",
fields: fields{
dataType: STRING,
name: "",
value: "STRING",
},
want: "STRING",
}, {
name: "GetValue-BLOB",
fields: fields{
dataType: BLOB,
name: "",
value: []byte("BLOB"),
},
want: []byte("BLOB"),
}, {
name: "GetValue-TIMESTAMP",
fields: fields{
dataType: TIMESTAMP,
name: "",
value: int64(65535),
},
want: int64(65535),
}, {
name: "GetValue-DATE",
fields: fields{
dataType: DATE,
name: "",
value: time.Date(2024, time.Month(4), 1, 0, 0, 0, 0, time.UTC),
},
want: time.Date(2024, time.Month(4), 1, 0, 0, 0, 0, time.UTC),
},
}
for _, tt := range tests {
Expand Down Expand Up @@ -408,6 +473,30 @@ func TestField_GetText(t *testing.T) {
value: int32(1),
},
want: "1",
}, {
name: "GetText-04",
fields: fields{
dataType: STRING,
name: "",
value: "STRING",
},
want: "STRING",
}, {
name: "GetText-05",
fields: fields{
dataType: BLOB,
name: "",
value: []byte("BLOB"),
},
want: "0x424c4f42",
}, {
name: "GetText-06",
fields: fields{
dataType: DATE,
name: "",
value: time.Date(2024, time.Month(4), 1, 0, 0, 0, 0, time.UTC),
},
want: "2024-04-01",
},
}
for _, tt := range tests {
Expand Down
4 changes: 2 additions & 2 deletions client/rpcdataset.go
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ func (s *IoTDBRpcDataSet) getString(columnIndex int, dataType TSDataType) string
if err != nil {
return ""
}
return date.Format("2006-01-02")
return date.Format(time.DateOnly)

Check failure on line 202 in client/rpcdataset.go

View workflow job for this annotation

GitHub Actions / Build (ubuntu-latest, 1.13)

undefined: time.DateOnly
default:
return ""
}
Expand Down Expand Up @@ -380,7 +380,7 @@ func (s *IoTDBRpcDataSet) scan(dest ...interface{}) error {
if err != nil {
*t = ""
}
*t = date.Format("2006-01-02")
*t = date.Format(time.DateOnly)

Check failure on line 383 in client/rpcdataset.go

View workflow job for this annotation

GitHub Actions / Build (ubuntu-latest, 1.13)

undefined: time.DateOnly
default:
return fmt.Errorf("dest[%d] types must be *time.Time or *string", i)
}
Expand Down
81 changes: 64 additions & 17 deletions client/rpcdataset_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
package client

import (
"bytes"
"reflect"
"testing"
"time"
Expand All @@ -28,23 +29,49 @@ import (
)

func createIoTDBRpcDataSet() *IoTDBRpcDataSet {
columns := []string{"root.ln.device1.restart_count", "root.ln.device1.price", "root.ln.device1.tick_count", "root.ln.device1.temperature", "root.ln.device1.description", "root.ln.device1.status"}
dataTypes := []string{"INT32", "DOUBLE", "INT64", "FLOAT", "TEXT", "BOOLEAN"}
columns := []string{
"root.ln.device1.restart_count",
"root.ln.device1.price",
"root.ln.device1.tick_count",
"root.ln.device1.temperature",
"root.ln.device1.description",
"root.ln.device1.status",
"root.ln.device1.description_string",
"root.ln.device1.description_blob",
"root.ln.device1.date",
"root.ln.device1.timestamp",
}
dataTypes := []string{"INT32", "DOUBLE", "INT64", "FLOAT", "TEXT", "BOOLEAN", "STRING", "BLOB", "DATE", "TIMESTAMP"}
columnNameIndex := map[string]int32{
"root.ln.device1.restart_count": 2,
"root.ln.device1.price": 1,
"root.ln.device1.tick_count": 5,
"root.ln.device1.temperature": 4,
"root.ln.device1.description": 0,
"root.ln.device1.status": 3,
"root.ln.device1.restart_count": 2,
"root.ln.device1.price": 1,
"root.ln.device1.tick_count": 5,
"root.ln.device1.temperature": 4,
"root.ln.device1.description": 0,
"root.ln.device1.status": 3,
"root.ln.device1.description_string": 6,
"root.ln.device1.description_blob": 7,
"root.ln.device1.date": 8,
"root.ln.device1.timestamp": 9,
}
var queyrId int64 = 1
var sessionId int64 = 1
var client *rpc.IClientRPCServiceClient = nil
queryDataSet := rpc.TSQueryDataSet{
Time: []byte{0, 0, 1, 118, 76, 52, 0, 236, 0, 0, 1, 118, 76, 52, 25, 228, 0, 0, 1, 118, 76, 52, 41, 42, 0, 0, 1, 118, 76, 52, 243, 148, 0, 0, 1, 118, 76, 95, 98, 255},
ValueList: [][]byte{{0, 0, 0, 13, 84, 101, 115, 116, 32, 68, 101, 118, 105, 99, 101, 32, 49, 0, 0, 0, 13, 84, 101, 115, 116, 32, 68, 101, 118, 105, 99, 101, 32, 49, 0, 0, 0, 13, 84, 101, 115, 116, 32, 68, 101, 118, 105, 99, 101, 32, 49, 0, 0, 0, 13, 84, 101, 115, 116, 32, 68, 101, 118, 105, 99, 101, 32, 49, 0, 0, 0, 13, 84, 101, 115, 116, 32, 68, 101, 118, 105, 99, 101, 32, 49}, {64, 159, 16, 204, 204, 204, 204, 205, 64, 159, 16, 204, 204, 204, 204, 205, 64, 159, 16, 204, 204, 204, 204, 205, 64, 159, 16, 204, 204, 204, 204, 205, 64, 159, 16, 204, 204, 204, 204, 205}, {0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1}, {1, 1, 1, 1, 1}, {65, 65, 153, 154, 65, 65, 153, 154, 65, 65, 153, 154, 65, 65, 153, 154, 65, 65, 153, 154}, {0, 0, 0, 0, 0, 50, 220, 213, 0, 0, 0, 0, 0, 50, 220, 213, 0, 0, 0, 0, 0, 50, 220, 213, 0, 0, 0, 0, 0, 50, 220, 213, 0, 0, 0, 0, 0, 50, 220, 213}},
BitmapList: [][]byte{{248}, {248}, {248}, {248}, {248}, {248}},
Time: []byte{0, 0, 1, 118, 76, 52, 0, 236, 0, 0, 1, 118, 76, 52, 25, 228, 0, 0, 1, 118, 76, 52, 41, 42, 0, 0, 1, 118, 76, 52, 243, 148, 0, 0, 1, 118, 76, 95, 98, 255},
ValueList: [][]byte{
{0, 0, 0, 13, 84, 101, 115, 116, 32, 68, 101, 118, 105, 99, 101, 32, 49, 0, 0, 0, 13, 84, 101, 115, 116, 32, 68, 101, 118, 105, 99, 101, 32, 49, 0, 0, 0, 13, 84, 101, 115, 116, 32, 68, 101, 118, 105, 99, 101, 32, 49, 0, 0, 0, 13, 84, 101, 115, 116, 32, 68, 101, 118, 105, 99, 101, 32, 49, 0, 0, 0, 13, 84, 101, 115, 116, 32, 68, 101, 118, 105, 99, 101, 32, 49},
{64, 159, 16, 204, 204, 204, 204, 205, 64, 159, 16, 204, 204, 204, 204, 205, 64, 159, 16, 204, 204, 204, 204, 205, 64, 159, 16, 204, 204, 204, 204, 205, 64, 159, 16, 204, 204, 204, 204, 205},
{0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1},
{1, 1, 1, 1, 1},
{65, 65, 153, 154, 65, 65, 153, 154, 65, 65, 153, 154, 65, 65, 153, 154, 65, 65, 153, 154},
{0, 0, 0, 0, 0, 50, 220, 213, 0, 0, 0, 0, 0, 50, 220, 213, 0, 0, 0, 0, 0, 50, 220, 213, 0, 0, 0, 0, 0, 50, 220, 213, 0, 0, 0, 0, 0, 50, 220, 213},
{0, 0, 0, 13, 84, 101, 115, 116, 32, 68, 101, 118, 105, 99, 101, 32, 49, 0, 0, 0, 13, 84, 101, 115, 116, 32, 68, 101, 118, 105, 99, 101, 32, 49, 0, 0, 0, 13, 84, 101, 115, 116, 32, 68, 101, 118, 105, 99, 101, 32, 49, 0, 0, 0, 13, 84, 101, 115, 116, 32, 68, 101, 118, 105, 99, 101, 32, 49, 0, 0, 0, 13, 84, 101, 115, 116, 32, 68, 101, 118, 105, 99, 101, 32, 49},
{0, 0, 0, 13, 84, 101, 115, 116, 32, 68, 101, 118, 105, 99, 101, 32, 49, 0, 0, 0, 13, 84, 101, 115, 116, 32, 68, 101, 118, 105, 99, 101, 32, 49, 0, 0, 0, 13, 84, 101, 115, 116, 32, 68, 101, 118, 105, 99, 101, 32, 49, 0, 0, 0, 13, 84, 101, 115, 116, 32, 68, 101, 118, 105, 99, 101, 32, 49, 0, 0, 0, 13, 84, 101, 115, 116, 32, 68, 101, 118, 105, 99, 101, 32, 49},
{1, 52, 216, 17, 1, 52, 216, 17, 1, 52, 216, 17, 1, 52, 216, 17, 1, 52, 216, 17},
{0, 0, 0, 0, 0, 50, 220, 213, 0, 0, 0, 0, 0, 50, 220, 213, 0, 0, 0, 0, 0, 50, 220, 213, 0, 0, 0, 0, 0, 50, 220, 213, 0, 0, 0, 0, 0, 50, 220, 213},
},
BitmapList: [][]byte{{248}, {248}, {248}, {248}, {248}, {248}, {248}, {248}, {248}, {248}},
}
return NewIoTDBRpcDataSet("select * from root.ln.device1", columns, dataTypes, columnNameIndex, queyrId, client, sessionId, &queryDataSet, false, DefaultFetchSize, nil)
}
Expand Down Expand Up @@ -558,11 +585,27 @@ func TestIoTDBRpcDataSet_getRowRecord(t *testing.T) {
}, {
name: "root.ln.device1.description",
dataType: TEXT,
value: string("Test Device 1"),
value: "Test Device 1",
}, {
name: "root.ln.device1.status",
dataType: BOOLEAN,
value: bool(true),
value: true,
}, {
name: "root.ln.device1.description_string",
dataType: STRING,
value: "Test Device 1",
}, {
name: "root.ln.device1.description_blob",
dataType: BLOB,
value: []byte("Test Device 1"),
}, {
name: "root.ln.device1.date",
dataType: DATE,
value: time.Date(2024, time.April, 1, 0, 0, 0, 0, time.UTC),
}, {
name: "root.ln.device1.timestamp",
dataType: TIMESTAMP,
value: int64(3333333),
},
},
},
Expand All @@ -583,10 +626,14 @@ func TestIoTDBRpcDataSet_getRowRecord(t *testing.T) {
for i := 0; i < len(got.fields); i++ {
gotField := got.fields[i]
wantField := tt.want.fields[i]

if gotField.dataType != wantField.dataType || gotField.name != wantField.name || gotField.value != wantField.value {
match = false

if gotField.dataType != BLOB {
if gotField.dataType != wantField.dataType || gotField.name != wantField.name || gotField.value != wantField.value {
match = false
}
} else {
if gotField.dataType != wantField.dataType || gotField.name != wantField.name || !bytes.Equal(gotField.value.([]byte), wantField.value.([]byte)) {
match = false
}
}
}
if !match {
Expand Down
Loading

0 comments on commit 7128a5f

Please sign in to comment.