gzip_test.go 1.1 KB

12345678910111213141516171819202122232425262728293031323334
  1. // Copyright 2020-2021 InfluxData, Inc.. All rights reserved.
  2. // Use of this source code is governed by MIT
  3. // license that can be found in the LICENSE file.
  4. package gzip_test
  5. import (
  6. "bytes"
  7. egzip "compress/gzip"
  8. "io/ioutil"
  9. "testing"
  10. "github.com/influxdata/influxdb-client-go/v2/internal/gzip"
  11. )
  12. func TestGzip(t *testing.T) {
  13. text := `Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.`
  14. inputBuffer := bytes.NewBuffer([]byte(text))
  15. r, err := gzip.CompressWithGzip(inputBuffer)
  16. if err != nil {
  17. t.Fatal(err)
  18. }
  19. ur, err := egzip.NewReader(r)
  20. if err != nil {
  21. t.Fatal(err)
  22. }
  23. res, err := ioutil.ReadAll(ur)
  24. if err != nil {
  25. t.Fatal(err)
  26. }
  27. if string(res) != text {
  28. t.Fatal("text did not encode or possibly decode properly")
  29. }
  30. }