Skip to content

Commit

Permalink
Add unit test for GZIP method
Browse files Browse the repository at this point in the history
  • Loading branch information
Bobby Shannon committed Jul 3, 2017
1 parent 599aa5d commit 669ad0b
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions plugins/outputs/influxdb/client/http_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package client

import (
"bytes"
"compress/gzip"
"fmt"
"net/http"
"net/http/httptest"
Expand Down Expand Up @@ -341,3 +342,22 @@ func TestHTTPClient_Query_JSONDecodeError(t *testing.T) {
assert.Error(t, err)
assert.Contains(t, err.Error(), "json")
}

func TestGzipCompression(t *testing.T) {
// Compress the payload using GZIP.
payload := []byte("cpu value=99\n")
compressed, err := compressWithGzip(payload)
assert.Nil(t, err)

// GUNZIP the compressed payload and make sure
// that its original value has not changed.
r, err := gzip.NewReader(bytes.NewReader(compressed))
assert.Nil(t, err)
r.Close()

var uncompressed bytes.Buffer
_, err = uncompressed.ReadFrom(r)
assert.Nil(t, err)

assert.Equal(t, payload, uncompressed.Bytes())
}

0 comments on commit 669ad0b

Please sign in to comment.