forked from scylladb/gocql
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added test cases for compressor to improve testing coverage
- Loading branch information
Phillip Couto
committed
Sep 23, 2014
1 parent
f68d4c0
commit 8e84296
Showing
1 changed file
with
38 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.") | ||
} | ||
} |