@@ -93,22 +93,51 @@ func TestGetInstanceName(t *testing.T) {
9393
9494func TestGetUserDetails (t * testing.T ) {
9595 tests := []struct {
96- description string
97- getUserFails bool
98- GetUserResp * secretsmanager.User
99- isValid bool
100- expectedUserName string
101- expectedDescription string
96+ description string
97+ getUserFails bool
98+ GetUserResp * secretsmanager.User
99+ isValid bool
100+ expectedOutput string
102101 }{
103102 {
104103 description : "base" ,
105104 GetUserResp : & secretsmanager.User {
106105 Username : utils .Ptr (testUserName ),
107106 Description : utils .Ptr (testDescription ),
108107 },
109- isValid : true ,
110- expectedUserName : testUserName ,
111- expectedDescription : testDescription ,
108+ isValid : true ,
109+ expectedOutput : fmt .Sprintf ("%q (%s)" , testUserName , testDescription ),
110+ },
111+ {
112+ description : "user has no description" ,
113+ GetUserResp : & secretsmanager.User {
114+ Username : utils .Ptr (testUserName ),
115+ },
116+ isValid : true ,
117+ expectedOutput : fmt .Sprintf ("%q" , testUserName ),
118+ },
119+ {
120+ description : "user has empty description" ,
121+ GetUserResp : & secretsmanager.User {
122+ Username : utils .Ptr (testUserName ),
123+ Description : utils .Ptr ("" ),
124+ },
125+ isValid : true ,
126+ expectedOutput : fmt .Sprintf ("%q" , testUserName ),
127+ },
128+ {
129+ description : "user has empty username" ,
130+ GetUserResp : & secretsmanager.User {
131+ Username : utils .Ptr ("" ),
132+ },
133+ isValid : false ,
134+ },
135+ {
136+ description : "user has no username" ,
137+ GetUserResp : & secretsmanager.User {
138+ Username : nil ,
139+ },
140+ isValid : false ,
112141 },
113142 {
114143 description : "get user fails" ,
@@ -124,7 +153,7 @@ func TestGetUserDetails(t *testing.T) {
124153 getUserResp : tt .GetUserResp ,
125154 }
126155
127- username , description , err := GetUserDetails (context .Background (), client , testProjectId , testInstanceId , testUserId )
156+ userLabel , err := GetUserLabel (context .Background (), client , testProjectId , testInstanceId , testUserId )
128157
129158 if tt .isValid && err != nil {
130159 t .Errorf ("failed on valid input" )
@@ -135,11 +164,8 @@ func TestGetUserDetails(t *testing.T) {
135164 if ! tt .isValid {
136165 return
137166 }
138- if username != tt .expectedUserName {
139- t .Errorf ("expected username to be %s, got %s" , tt .expectedUserName , username )
140- }
141- if description != tt .expectedDescription {
142- t .Errorf ("expected description to be %s, got %s" , tt .expectedDescription , description )
167+ if userLabel != tt .expectedOutput {
168+ t .Errorf ("expected user label to be %s, got %s" , tt .expectedOutput , userLabel )
143169 }
144170 })
145171 }
0 commit comments