Skip to content

Commit

Permalink
chore: add tests for boolean scans and timestamp recognition
Browse files Browse the repository at this point in the history
  • Loading branch information
yquansah authored and haaawk committed Oct 26, 2023
1 parent a6918fb commit fce76c0
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 4 deletions.
1 change: 1 addition & 0 deletions libsql/internal/hrana/value.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ func (v Value) ToValue(columnType *string) any {
}
}
}

return v.Value
}

Expand Down
48 changes: 44 additions & 4 deletions libsql/internal/hrana/value_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,15 @@ import (
"reflect"
"strconv"
"testing"
"time"
)

func TestValueToValue(t *testing.T) {
tests := []struct {
name string
value Value
want any
name string
columnType string
value Value
want any
}{
{
name: "null",
Expand Down Expand Up @@ -53,16 +55,30 @@ func TestValueToValue(t *testing.T) {
},
want: 3.14,
},
{
name: "timestamp",
columnType: "TIMESTAMP",
value: Value{
Type: "text",
Value: "0001-01-01 01:00:00+00:00",
},
want: time.Time{}.Add(time.Hour),
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got := tt.value.ToValue(nil)
var columnType *string = nil
if tt.columnType != "" {
columnType = &tt.columnType
}
got := tt.value.ToValue(columnType)
if !reflect.DeepEqual(got, tt.want) {
t.Errorf("ToValue() = %v, want %v", got, tt.want)
}
})
}
}

func TestToValue(t *testing.T) {
tests := []struct {
name string
Expand Down Expand Up @@ -109,6 +125,22 @@ func TestToValue(t *testing.T) {
Value: 3.14,
},
},
{
name: "boolean",
value: true,
want: Value{
Type: "integer",
Value: "1",
},
},
{
name: "timestamp",
value: time.Time{}.Add(time.Hour),
want: Value{
Type: "text",
Value: "0001-01-01 01:00:00+00:00",
},
},
{
name: "unsupported",
value: make(chan int),
Expand Down Expand Up @@ -175,6 +207,14 @@ func TestMarshal(t *testing.T) {
},
marshaled: `{"type":"float","value":3.14}`,
},
{
name: "timestamp",
value: Value{
Type: "text",
Value: time.Time{}.Add(time.Hour),
},
marshaled: `{"type":"text","value":"0001-01-01T01:00:00Z"}`,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
Expand Down

0 comments on commit fce76c0

Please sign in to comment.