sdk_test.go 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. // Copyright 2015 The Go Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style
  3. // license that can be found in the LICENSE file.
  4. package google
  5. import "testing"
  6. func TestSDKConfig(t *testing.T) {
  7. sdkConfigPath = func() (string, error) {
  8. return "testdata/gcloud", nil
  9. }
  10. tests := []struct {
  11. account string
  12. accessToken string
  13. err bool
  14. }{
  15. {"", "bar_access_token", false},
  16. {"foo@example.com", "foo_access_token", false},
  17. {"bar@example.com", "bar_access_token", false},
  18. {"baz@serviceaccount.example.com", "", true},
  19. }
  20. for _, tt := range tests {
  21. c, err := NewSDKConfig(tt.account)
  22. if got, want := err != nil, tt.err; got != want {
  23. if !tt.err {
  24. t.Errorf("expected no error, got error: %v", tt.err, err)
  25. } else {
  26. t.Errorf("expected error, got none")
  27. }
  28. continue
  29. }
  30. if err != nil {
  31. continue
  32. }
  33. tok := c.initialToken
  34. if tok == nil {
  35. t.Errorf("expected token %q, got: nil", tt.accessToken)
  36. continue
  37. }
  38. if tok.AccessToken != tt.accessToken {
  39. t.Errorf("expected token %q, got: %q", tt.accessToken, tok.AccessToken)
  40. }
  41. }
  42. }