MCPcopy
hub / github.com/minio/minio-go / TestGetBucketPolicy

Function TestGetBucketPolicy

core_test.go:313–373  ·  view source on GitHub ↗

Tests get bucket policy core API.

(t *testing.T)

Source from the content-addressed store, hash-verified

311
312// Tests get bucket policy core API.
313func TestGetBucketPolicy(t *testing.T) {
314 if os.Getenv(serverEndpoint) == "" {
315 t.Skip("SERVER_ENDPOINT not set")
316 }
317 if testing.Short() {
318 t.Skip("skipping functional tests for short runs")
319 }
320
321 // Instantiate new minio client object.
322 c, err := NewCore(
323 os.Getenv(serverEndpoint),
324 &Options{
325 Creds: credentials.NewStaticV4(os.Getenv(accessKey), os.Getenv(secretKey), ""),
326 Secure: mustParseBool(os.Getenv(enableSecurity)),
327 })
328 if err != nil {
329 t.Fatal("Error:", err)
330 }
331
332 // Enable to debug
333 // c.TraceOn(os.Stderr)
334
335 // Set user agent.
336 c.SetAppInfo("MinIO-go-FunctionalTest", "0.1.0")
337
338 // Generate a new random bucket name.
339 bucketName := randString(60, rand.NewSource(time.Now().UnixNano()), "minio-go-test")
340
341 // Make a new bucket.
342 err = c.MakeBucket(context.Background(), bucketName, MakeBucketOptions{Region: "us-east-1"})
343 if err != nil {
344 t.Fatal("Error:", err, bucketName)
345 }
346
347 // Verify if bucket exits and you have access.
348 var exists bool
349 exists, err = c.BucketExists(context.Background(), bucketName)
350 if err != nil {
351 t.Fatal("Error:", err, bucketName)
352 }
353 if !exists {
354 t.Fatal("Error: could not find ", bucketName)
355 }
356
357 // Asserting the default bucket policy.
358 bucketPolicy, err := c.GetBucketPolicy(context.Background(), bucketName)
359 if err != nil {
360 errResp := ToErrorResponse(err)
361 if errResp.Code != NoSuchBucketPolicy {
362 t.Error("Error:", err, bucketName)
363 }
364 }
365 if bucketPolicy != "" {
366 t.Errorf("Bucket policy expected %#v, got %#v", "", bucketPolicy)
367 }
368
369 err = c.RemoveBucket(context.Background(), bucketName)
370 if err != nil {

Callers

nothing calls this directly

Calls 11

GetBucketPolicyMethod · 0.95
NewStaticV4Function · 0.92
NewCoreFunction · 0.85
ToErrorResponseFunction · 0.85
SetAppInfoMethod · 0.80
MakeBucketMethod · 0.80
BucketExistsMethod · 0.80
RemoveBucketMethod · 0.80
mustParseBoolFunction · 0.70
randStringFunction · 0.70
ErrorMethod · 0.45

Tested by

no test coverage detected