Skip to content

Commit

Permalink
Added test cases for compressor to improve testing coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
Phillip Couto committed Sep 23, 2014
1 parent f68d4c0 commit 8e84296
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions compressor_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package gocql

import (
"bytes"
"code.google.com/p/snappy-go/snappy"
"testing"
)

func TestSnappyCompressor(t *testing.T) {
c := SnappyCompressor{}
if c.Name() != "snappy" {
t.Fatalf("expected name to be 'snappy', got %v", c.Name())
}

str := "My Test String"
//Test Encoding
if expected, err := snappy.Encode(nil, []byte(str)); err != nil {
t.Fatalf("failed to encode '%v' with error %v", str, err)
} else if res, err := c.Encode([]byte(str)); err != nil {
t.Fatalf("failed to encode '%v' with error %v", str, err)
} else if bytes.Compare(expected, res) != 0 {
t.Fatal("failed to match the expected encoded value with the result encoded value.")
}

val, err := c.Encode([]byte(str))
if err != nil {
t.Fatalf("failed to encode '%v' with error '%v'", str, err)
}

//Test Decoding
if expected, err := snappy.Decode(nil, val); err != nil {
t.Fatalf("failed to decode '%v' with error %v", val, err)
} else if res, err := c.Decode(val); err != nil {
t.Fatalf("failed to decode '%v' with error %v", val, err)
} else if bytes.Compare(expected, res) != 0 {
t.Fatal("failed to match the expected decoded value with the result decoded value.")
}
}

0 comments on commit 8e84296

Please sign in to comment.