Skip to content

Commit

Permalink
Added integration test and fixed a bug with zero length data
Browse files Browse the repository at this point in the history
  • Loading branch information
0x6e6562 committed Feb 24, 2014
1 parent a4591a1 commit 1dc336c
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
14 changes: 9 additions & 5 deletions cassandra_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ package gocql
import (
"bytes"
"flag"
"math/big"
"reflect"
"sort"
"strings"
Expand Down Expand Up @@ -78,6 +79,7 @@ func TestCRUD(t *testing.T) {
views bigint,
protected boolean,
modified timestamp,
rating decimal,
tags set<varchar>,
attachments map<varchar, text>,
PRIMARY KEY (title, revid)
Expand All @@ -87,10 +89,10 @@ func TestCRUD(t *testing.T) {

for _, page := range pageTestData {
if err := session.Query(`INSERT INTO page
(title, revid, body, views, protected, modified, tags, attachments)
VALUES (?, ?, ?, ?, ?, ?, ?, ?)`,
(title, revid, body, views, protected, modified, rating, tags, attachments)
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)`,
page.Title, page.RevId, page.Body, page.Views, page.Protected,
page.Modified, page.Tags, page.Attachments).Exec(); err != nil {
page.Modified, page.Rating, page.Tags, page.Attachments).Exec(); err != nil {
t.Fatal("insert:", err)
}
}
Expand All @@ -106,11 +108,11 @@ func TestCRUD(t *testing.T) {
for _, original := range pageTestData {
page := new(Page)
err := session.Query(`SELECT title, revid, body, views, protected, modified,
tags, attachments
tags, attachments, rating
FROM page WHERE title = ? AND revid = ? LIMIT 1`,
original.Title, original.RevId).Scan(&page.Title, &page.RevId,
&page.Body, &page.Views, &page.Protected, &page.Modified, &page.Tags,
&page.Attachments)
&page.Attachments, &page.Rating)
if err != nil {
t.Error("select page:", err)
continue
Expand Down Expand Up @@ -301,6 +303,7 @@ type Page struct {
Views int64
Protected bool
Modified time.Time
Rating *big.Rat
Tags []string
Attachments map[string]Attachment
}
Expand All @@ -312,6 +315,7 @@ var pageTestData = []*Page{
Title: "Frontpage",
RevId: TimeUUID(),
Body: "Welcome to this wiki page!",
Rating: big.NewRat(871298379, 243),
Modified: time.Date(2013, time.August, 13, 9, 52, 3, 0, time.UTC),
Tags: []string{"start", "important", "test"},
Attachments: map[string]Attachment{
Expand Down
8 changes: 5 additions & 3 deletions marshal.go
Original file line number Diff line number Diff line change
Expand Up @@ -704,9 +704,11 @@ func unmarshalDecimal(info *TypeInfo, data []byte, value interface{}) error {
case Unmarshaler:
return v.UnmarshalCQL(info, data)
case **big.Rat:
denom := new(big.Int).SetBytes(data[0:4])
num := new(big.Int).SetBytes(data[4:])
*v = new(big.Rat).SetFrac(num, denom)
if len(data) > 4 {
denom := new(big.Int).SetBytes(data[0:4])
num := new(big.Int).SetBytes(data[4:])
*v = new(big.Rat).SetFrac(num, denom)
}
return nil
}
return unmarshalErrorf("can not unmarshal %s into %T", info, value)
Expand Down

0 comments on commit 1dc336c

Please sign in to comment.