legacy_export_test.go 949 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. // Copyright 2019 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 impl
  5. import (
  6. "bytes"
  7. "compress/gzip"
  8. "io/ioutil"
  9. "math"
  10. "strings"
  11. "testing"
  12. )
  13. func TestCompressGZIP(t *testing.T) {
  14. tests := []string{
  15. "",
  16. "a",
  17. "ab",
  18. "abc",
  19. strings.Repeat("a", math.MaxUint16-1),
  20. strings.Repeat("b", math.MaxUint16),
  21. strings.Repeat("c", math.MaxUint16+1),
  22. strings.Repeat("abcdefghijklmnopqrstuvwxyz", math.MaxUint16-13),
  23. }
  24. for _, want := range tests {
  25. rb := bytes.NewReader(Export{}.CompressGZIP([]byte(want)))
  26. zr, err := gzip.NewReader(rb)
  27. if err != nil {
  28. t.Errorf("unexpected gzip.NewReader error: %v", err)
  29. }
  30. b, err := ioutil.ReadAll(zr)
  31. if err != nil {
  32. t.Errorf("unexpected ioutil.ReadAll error: %v", err)
  33. }
  34. if got := string(b); got != want {
  35. t.Errorf("output mismatch: got %q, want %q", got, want)
  36. }
  37. }
  38. }