Skip to content

Commit 84b0c7d

Browse files
committed
Add tests
1 parent e9d7299 commit 84b0c7d

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

internal/translation/dbuser/internal_test.go

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,34 @@ func TestToAndFromAtlas(t *testing.T) {
105105
}
106106
}
107107

108+
func TestToAtlas(t *testing.T) {
109+
for _, tc := range []struct {
110+
title string
111+
user *User
112+
atlasUser *admin.CloudDatabaseUser
113+
}{
114+
{
115+
title: "Empty description should be converted as empty string, not nil",
116+
user: func() *User {
117+
user := defaultTestUser()
118+
user.Description = ""
119+
return user
120+
}(),
121+
atlasUser: func() *admin.CloudDatabaseUser {
122+
inAtlas := defaultTestAtlasUser()
123+
inAtlas.Description = pointer.MakePtr("")
124+
return inAtlas
125+
}(),
126+
},
127+
} {
128+
t.Run(tc.title, func(t *testing.T) {
129+
atlasUser, err := toAtlas(tc.user)
130+
require.NoError(t, err)
131+
assert.Equal(t, tc.atlasUser, atlasUser)
132+
})
133+
}
134+
}
135+
108136
func TestToAtlasDateFailure(t *testing.T) {
109137
user := defaultTestUser()
110138
user.DeleteAfterDate = "bad-date-string"
@@ -143,5 +171,7 @@ func defaultTestAtlasUser() *admin.CloudDatabaseUser {
143171
GroupId: testProjectID,
144172
Password: pointer.MakePtr(testPassword),
145173
Username: testUsername,
174+
Scopes: pointer.MakePtr([]admin.UserScope{}),
175+
Description: pointer.MakePtr(""),
146176
}
147177
}

0 commit comments

Comments
 (0)