Tests GetObject to return Content-Encoding properly set and overrides any auto decoding.
(t *testing.T)
| 238 | // Tests GetObject to return Content-Encoding properly set |
| 239 | // and overrides any auto decoding. |
| 240 | func TestGetObjectContentEncoding(t *testing.T) { |
| 241 | if os.Getenv(serverEndpoint) == "" { |
| 242 | t.Skip("SERVER_ENDPOINT not set") |
| 243 | } |
| 244 | if testing.Short() { |
| 245 | t.Skip("skipping functional tests for the short runs") |
| 246 | } |
| 247 | |
| 248 | // Instantiate new minio core client object. |
| 249 | c, err := NewCore( |
| 250 | os.Getenv(serverEndpoint), |
| 251 | &Options{ |
| 252 | Creds: credentials.NewStaticV4(os.Getenv(accessKey), os.Getenv(secretKey), ""), |
| 253 | Secure: mustParseBool(os.Getenv(enableSecurity)), |
| 254 | }) |
| 255 | if err != nil { |
| 256 | t.Fatal("Error:", err) |
| 257 | } |
| 258 | |
| 259 | // Enable tracing, write to stderr. |
| 260 | // c.TraceOn(os.Stderr) |
| 261 | |
| 262 | // Set user agent. |
| 263 | c.SetAppInfo("MinIO-go-FunctionalTest", "0.1.0") |
| 264 | |
| 265 | // Generate a new random bucket name. |
| 266 | bucketName := randString(60, rand.NewSource(time.Now().UnixNano()), "minio-go-test") |
| 267 | |
| 268 | // Make a new bucket. |
| 269 | err = c.MakeBucket(context.Background(), bucketName, MakeBucketOptions{Region: "us-east-1"}) |
| 270 | if err != nil { |
| 271 | t.Fatal("Error:", err, bucketName) |
| 272 | } |
| 273 | |
| 274 | // Generate data more than 32K |
| 275 | buf := bytes.Repeat([]byte("3"), rand.Intn(1<<20)+32*1024) |
| 276 | |
| 277 | // Save the data |
| 278 | objectName := randString(60, rand.NewSource(time.Now().UnixNano()), "") |
| 279 | _, err = c.Client.PutObject(context.Background(), bucketName, objectName, bytes.NewReader(buf), int64(len(buf)), PutObjectOptions{ |
| 280 | ContentEncoding: "gzip", |
| 281 | }) |
| 282 | if err != nil { |
| 283 | t.Fatal("Error:", err, bucketName, objectName) |
| 284 | } |
| 285 | |
| 286 | rwc, objInfo, _, err := c.GetObject(context.Background(), bucketName, objectName, GetObjectOptions{}) |
| 287 | if err != nil { |
| 288 | t.Fatalf("Error: %v", err) |
| 289 | } |
| 290 | rwc.Close() |
| 291 | if objInfo.Size != int64(len(buf)) { |
| 292 | t.Fatalf("Unexpected size of the object %v, expected %v", objInfo.Size, len(buf)) |
| 293 | } |
| 294 | value, ok := objInfo.Metadata["Content-Encoding"] |
| 295 | if !ok { |
| 296 | t.Fatalf("Expected Content-Encoding metadata to be set.") |
| 297 | } |
nothing calls this directly
no test coverage detected