@@ -18,33 +18,61 @@ func TestNewService(t *testing.T) {
1818 ctx := context .TODO ()
1919 userEmail := "mock-email@mock-project.iam.gserviceaccount.com"
2020 serviceAccountFile := "testdata/service_account.json"
21- scope := "admin.AdminDirectoryGroupReadonlyScope, admin.AdminDirectoryGroupMemberReadonlyScope, admin.AdminDirectoryUserReadonlyScope"
21+ scopes := []string {
22+ "https://www.googleapis.com/auth/admin.directory.group.readonly" ,
23+ "https://www.googleapis.com/auth/admin.directory.group.member.readonly" ,
24+ "https://www.googleapis.com/auth/admin.directory.user.readonly" ,
25+ }
2226
2327 serviceAccount , err := os .ReadFile (serviceAccountFile )
2428 if err != nil {
2529 t .Fatalf ("Error loading golden file: %s" , err )
2630 }
2731
28- svc , err := NewService (ctx , userEmail , serviceAccount , scope )
32+ config := DirectoryServiceConfig {
33+ Client : & http.Client {},
34+ UserEmail : userEmail ,
35+ ServiceAccount : serviceAccount ,
36+ Scopes : scopes ,
37+ UserAgent : "test-agent" ,
38+ }
39+
40+ svc , err := NewService (ctx , config )
2941 assert .NoError (t , err )
3042 assert .NotNil (t , svc )
3143 })
3244
3345 t .Run ("Should return a new Service with empty service account parameter" , func (t * testing.T ) {
3446 ctx := context .TODO ()
3547 userEmail := ""
36- scope := ""
48+ scopes := []string {}
49+
50+ config := DirectoryServiceConfig {
51+ Client : & http.Client {},
52+ UserEmail : userEmail ,
53+ ServiceAccount : nil ,
54+ Scopes : scopes ,
55+ UserAgent : "test-agent" ,
56+ }
3757
38- svc , err := NewService (ctx , userEmail , nil , scope )
58+ svc , err := NewService (ctx , config )
3959 assert .Error (t , err )
4060 assert .Nil (t , svc )
4161 })
4262
4363 t .Run ("Should return an error when scope is nil" , func (t * testing.T ) {
4464 ctx := context .TODO ()
45- userEmail := ""
65+ userEmail := "test@example.com"
66+
67+ config := DirectoryServiceConfig {
68+ Client : & http.Client {},
69+ UserEmail : userEmail ,
70+ ServiceAccount : []byte ("{}" ), // provide minimal valid JSON
71+ Scopes : nil ,
72+ UserAgent : "test-agent" ,
73+ }
4674
47- svc , err := NewService (ctx , userEmail , nil )
75+ svc , err := NewService (ctx , config )
4876 assert .Error (t , err )
4977 assert .Nil (t , svc )
5078 assert .ErrorIs (t , err , ErrGoogleClientScopeNil )
@@ -56,14 +84,26 @@ func TestNewDirectoryService(t *testing.T) {
5684 ctx := context .TODO ()
5785 userEmail := "mock-email@mock-project.iam.gserviceaccount.com"
5886 serviceAccountFile := "testdata/service_account.json"
59- scope := "admin.AdminDirectoryGroupReadonlyScope, admin.AdminDirectoryGroupMemberReadonlyScope, admin.AdminDirectoryUserReadonlyScope"
87+ scopes := []string {
88+ "https://www.googleapis.com/auth/admin.directory.group.readonly" ,
89+ "https://www.googleapis.com/auth/admin.directory.group.member.readonly" ,
90+ "https://www.googleapis.com/auth/admin.directory.user.readonly" ,
91+ }
6092
6193 serviceAccount , err := os .ReadFile (serviceAccountFile )
6294 if err != nil {
6395 t .Fatalf ("Error loading golden file: %s" , err )
6496 }
6597
66- svc , err := NewService (ctx , userEmail , serviceAccount , scope )
98+ config := DirectoryServiceConfig {
99+ Client : & http.Client {},
100+ UserEmail : userEmail ,
101+ ServiceAccount : serviceAccount ,
102+ Scopes : scopes ,
103+ UserAgent : "test-agent" ,
104+ }
105+
106+ svc , err := NewService (ctx , config )
67107 if err != nil {
68108 t .Fatalf ("Error creating a service: %s" , err )
69109 }
0 commit comments