compressed_test.go 897 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. // Copyright 2011 The Go Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style
  3. // license that can be found in the LICENSE file.
  4. package packet
  5. import (
  6. "bytes"
  7. "encoding/hex"
  8. "io"
  9. "io/ioutil"
  10. "testing"
  11. )
  12. func TestCompressed(t *testing.T) {
  13. packet, err := Read(readerFromHex(compressedHex))
  14. if err != nil {
  15. t.Errorf("failed to read Compressed: %s", err)
  16. return
  17. }
  18. c, ok := packet.(*Compressed)
  19. if !ok {
  20. t.Error("didn't find Compressed packet")
  21. return
  22. }
  23. contents, err := ioutil.ReadAll(c.Body)
  24. if err != nil && err != io.EOF {
  25. t.Error(err)
  26. return
  27. }
  28. expected, _ := hex.DecodeString(compressedExpectedHex)
  29. if !bytes.Equal(expected, contents) {
  30. t.Errorf("got:%x want:%x", contents, expected)
  31. }
  32. }
  33. const compressedHex = "a3013b2d90c4e02b72e25f727e5e496a5e49b11e1700"
  34. const compressedExpectedHex = "cb1062004d14c8fe636f6e74656e74732e0a"