File tree Expand file tree Collapse file tree 2 files changed +44
-8
lines changed
Expand file tree Collapse file tree 2 files changed +44
-8
lines changed Original file line number Diff line number Diff line change @@ -334,14 +334,7 @@ func (m *Manager) tokenPath(email string) string {
334334
335335// scopesToString joins scopes with spaces.
336336func scopesToString (scopes []string ) string {
337- result := ""
338- for i , s := range scopes {
339- if i > 0 {
340- result += " "
341- }
342- result += s
343- }
344- return result
337+ return strings .Join (scopes , " " )
345338}
346339
347340// openBrowser opens the default browser to the given URL.
Original file line number Diff line number Diff line change 1+ package oauth
2+
3+ import (
4+ "testing"
5+ )
6+
7+ func TestScopesToString (t * testing.T ) {
8+ tests := []struct {
9+ name string
10+ scopes []string
11+ want string
12+ }{
13+ {
14+ name : "empty scopes" ,
15+ scopes : []string {},
16+ want : "" ,
17+ },
18+ {
19+ name : "single scope" ,
20+ scopes : []string {"https://www.googleapis.com/auth/gmail.readonly" },
21+ want : "https://www.googleapis.com/auth/gmail.readonly" ,
22+ },
23+ {
24+ name : "multiple scopes" ,
25+ scopes : []string {"https://www.googleapis.com/auth/gmail.readonly" , "https://www.googleapis.com/auth/gmail.modify" },
26+ want : "https://www.googleapis.com/auth/gmail.readonly https://www.googleapis.com/auth/gmail.modify" ,
27+ },
28+ {
29+ name : "three scopes" ,
30+ scopes : []string {"scope1" , "scope2" , "scope3" },
31+ want : "scope1 scope2 scope3" ,
32+ },
33+ }
34+
35+ for _ , tt := range tests {
36+ t .Run (tt .name , func (t * testing.T ) {
37+ got := scopesToString (tt .scopes )
38+ if got != tt .want {
39+ t .Errorf ("scopesToString() = %q, want %q" , got , tt .want )
40+ }
41+ })
42+ }
43+ }
You can’t perform that action at this time.
0 commit comments