compressor_test.go 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. // +build all unit
  2. package gocql
  3. import (
  4. "bytes"
  5. "code.google.com/p/snappy-go/snappy"
  6. "testing"
  7. )
  8. func TestSnappyCompressor(t *testing.T) {
  9. c := SnappyCompressor{}
  10. if c.Name() != "snappy" {
  11. t.Fatalf("expected name to be 'snappy', got %v", c.Name())
  12. }
  13. str := "My Test String"
  14. //Test Encoding
  15. if expected, err := snappy.Encode(nil, []byte(str)); err != nil {
  16. t.Fatalf("failed to encode '%v' with error %v", str, err)
  17. } else if res, err := c.Encode([]byte(str)); err != nil {
  18. t.Fatalf("failed to encode '%v' with error %v", str, err)
  19. } else if bytes.Compare(expected, res) != 0 {
  20. t.Fatal("failed to match the expected encoded value with the result encoded value.")
  21. }
  22. val, err := c.Encode([]byte(str))
  23. if err != nil {
  24. t.Fatalf("failed to encode '%v' with error '%v'", str, err)
  25. }
  26. //Test Decoding
  27. if expected, err := snappy.Decode(nil, val); err != nil {
  28. t.Fatalf("failed to decode '%v' with error %v", val, err)
  29. } else if res, err := c.Decode(val); err != nil {
  30. t.Fatalf("failed to decode '%v' with error %v", val, err)
  31. } else if bytes.Compare(expected, res) != 0 {
  32. t.Fatal("failed to match the expected decoded value with the result decoded value.")
  33. }
  34. }