@@ -7,7 +7,6 @@ package profiler
77
88import (
99 "bytes"
10- "compress/gzip"
1110 "fmt"
1211 "io"
1312 "os"
@@ -112,7 +111,26 @@ func TestGzipDecodingRecompressorInvalidInput(t *testing.T) {
112111 })
113112}
114113
115- // checkZstdLevel checks that data is zstd-compressed with the given level
114+ // checkGzipLevel checks that data is gzip-compressed with the given level.
115+ func checkGzipLevel (t * testing.T , data []byte , level int ) {
116+ t .Helper ()
117+ require .NotEmpty (t , data )
118+ gr , err := kgzip .NewReader (bytes .NewReader (data ))
119+ require .NoError (t , err )
120+ in := new (bytes.Buffer )
121+ _ , err = io .Copy (in , gr )
122+ require .NoError (t , err )
123+ require .NoError (t , gr .Close ())
124+ out := new (bytes.Buffer )
125+ gw , err := kgzip .NewWriterLevel (out , level )
126+ require .NoError (t , err )
127+ _ , err = io .Copy (gw , in )
128+ require .NoError (t , err )
129+ require .NoError (t , gw .Close ())
130+ require .Equal (t , data , out .Bytes ())
131+ }
132+
133+ // checkZstdLevel checks that data is zstd-compressed with the given level.
116134func checkZstdLevel (t * testing.T , data []byte , level zstd.EncoderLevel ) {
117135 t .Helper ()
118136 require .NotEmpty (t , data )
@@ -149,19 +167,19 @@ func TestDebugCompressionEnv(t *testing.T) {
149167 t .Run ("explicit-gzip" , func (t * testing.T ) {
150168 t .Setenv ("DD_PROFILING_DEBUG_COMPRESSION_SETTINGS" , "gzip" )
151169 p := startTestProfiler (t , 1 , WithProfileTypes (HeapProfile , BlockProfile ), WithPeriod (time .Millisecond )).ReceiveProfile (t )
152- r , err := gzip .NewReader (bytes .NewReader (p .attachments ["delta-heap.pprof" ]))
153- require .NoError (t , err )
154- _ , err = io .Copy (io .Discard , r )
155- require .NoError (t , err )
170+ checkGzipLevel (t , p .attachments ["delta-heap.pprof" ], gzip6Compression .level )
156171 })
157172
158173 t .Run ("explicit-gzip-already-gzipped-input" , func (t * testing.T ) {
159174 t .Setenv ("DD_PROFILING_DEBUG_COMPRESSION_SETTINGS" , "gzip" )
160175 p := startTestProfiler (t , 1 , WithProfileTypes (CPUProfile ), WithPeriod (time .Millisecond )).ReceiveProfile (t )
161- r , err := gzip .NewReader (bytes .NewReader (p .attachments ["cpu.pprof" ]))
162- require .NoError (t , err )
163- _ , err = io .Copy (io .Discard , r )
164- require .NoError (t , err )
176+ checkGzipLevel (t , p .attachments ["cpu.pprof" ], gzip6Compression .level )
177+ })
178+
179+ t .Run ("gzip-1" , func (t * testing.T ) {
180+ t .Setenv ("DD_PROFILING_DEBUG_COMPRESSION_SETTINGS" , "gzip-1" )
181+ p := startTestProfiler (t , 1 , WithProfileTypes (HeapProfile ), WithPeriod (time .Millisecond )).ReceiveProfile (t )
182+ checkGzipLevel (t , p .attachments ["delta-heap.pprof" ], gzip1Compression .level )
165183 })
166184
167185 t .Run ("zstd-delta" , func (t * testing.T ) {
0 commit comments