You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

66 lines
1.6 KiB

  1. // Copyright 2014 Google LLC
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. package storage
  15. import (
  16. "context"
  17. "net/http"
  18. "testing"
  19. "cloud.google.com/go/internal/testutil"
  20. )
  21. func TestSetACL(t *testing.T) {
  22. ctx := context.Background()
  23. mt := &mockTransport{}
  24. client := mockClient(t, mt)
  25. bh := &ACLHandle{c: client, bucket: "B"}
  26. oh := &ACLHandle{c: client, bucket: "B", object: "O"}
  27. for _, test := range []struct {
  28. desc string
  29. f func() error
  30. want map[string]interface{}
  31. }{
  32. {
  33. desc: "bucket Set",
  34. f: func() error { return bh.Set(ctx, AllUsers, RoleReader) },
  35. want: map[string]interface{}{
  36. "bucket": "B",
  37. "entity": "allUsers",
  38. "role": "READER",
  39. },
  40. },
  41. {
  42. desc: "object Set",
  43. f: func() error { return oh.Set(ctx, ACLEntity("e"), RoleWriter) },
  44. want: map[string]interface{}{
  45. "bucket": "B",
  46. "entity": "e",
  47. "role": "WRITER",
  48. },
  49. }} {
  50. mt.addResult(&http.Response{StatusCode: 200, Body: bodyReader("{}")}, nil)
  51. if err := test.f(); err != nil {
  52. t.Fatal(err)
  53. }
  54. got := mt.gotJSONBody()
  55. if diff := testutil.Diff(got, test.want); diff != "" {
  56. t.Errorf("%s: %s", test.desc, diff)
  57. }
  58. }
  59. }