option_test.go 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. // Copyright 2015 Google Inc. All Rights Reserved.
  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 cloud
  15. import (
  16. "testing"
  17. "google.golang.org/cloud/internal/opts"
  18. )
  19. // Check that the slice passed into WithScopes is copied.
  20. func TestCopyScopes(t *testing.T) {
  21. o := &opts.DialOpt{}
  22. scopes := []string{"a", "b"}
  23. WithScopes(scopes...).Resolve(o)
  24. // Modify after using.
  25. scopes[1] = "c"
  26. if o.Scopes[0] != "a" || o.Scopes[1] != "b" {
  27. t.Errorf("want ['a', 'b'], got %+v", o.Scopes)
  28. }
  29. }
  30. // Check that resolution of WithScopes uses the most recent.
  31. // That is, it doesn't append scopes or ignore subsequent calls.
  32. func TestScopesOverride(t *testing.T) {
  33. o := &opts.DialOpt{}
  34. WithScopes("a").Resolve(o)
  35. WithScopes("b").Resolve(o)
  36. if want, got := 1, len(o.Scopes); want != got {
  37. t.Errorf("want %d scope, got %d", want, got)
  38. }
  39. if want, got := "b", o.Scopes[0]; want != got {
  40. t.Errorf("want %s scope, got %s", want, got)
  41. }
  42. }