Skip to content

Commit 592a62b

Browse files
committed
GitSSHKey, UserLink, GitAuthLink
1 parent 607e428 commit 592a62b

File tree

2 files changed

+44
-0
lines changed

2 files changed

+44
-0
lines changed

coderd/database/dbgen/generator.go

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,18 @@ func User(t *testing.T, db database.Store, orig database.User) database.User {
186186
return user
187187
}
188188

189+
func GitSSHKey(t *testing.T, db database.Store, orig database.GitSSHKey) database.GitSSHKey {
190+
key, err := db.InsertGitSSHKey(context.Background(), database.InsertGitSSHKeyParams{
191+
UserID: takeFirst(orig.UserID, uuid.New()),
192+
CreatedAt: takeFirst(orig.CreatedAt, time.Now()),
193+
UpdatedAt: takeFirst(orig.UpdatedAt, time.Now()),
194+
PrivateKey: takeFirst(orig.PrivateKey, ""),
195+
PublicKey: takeFirst(orig.PublicKey, ""),
196+
})
197+
require.NoError(t, err, "insert ssh key")
198+
return key
199+
}
200+
189201
func Organization(t *testing.T, db database.Store, orig database.Organization) database.Organization {
190202
org, err := db.InsertOrganization(context.Background(), database.InsertOrganizationParams{
191203
ID: takeFirst(orig.ID, uuid.New()),
@@ -340,6 +352,21 @@ func UserLink(t *testing.T, db database.Store, orig database.UserLink) database.
340352
return link
341353
}
342354

355+
func GitAuthLink(t *testing.T, db database.Store, orig database.GitAuthLink) database.GitAuthLink {
356+
link, err := db.InsertGitAuthLink(context.Background(), database.InsertGitAuthLinkParams{
357+
ProviderID: takeFirst(orig.ProviderID, uuid.New().String()),
358+
UserID: takeFirst(orig.UserID, uuid.New()),
359+
OAuthAccessToken: takeFirst(orig.OAuthAccessToken, uuid.NewString()),
360+
OAuthRefreshToken: takeFirst(orig.OAuthAccessToken, uuid.NewString()),
361+
OAuthExpiry: takeFirst(orig.OAuthExpiry, time.Now().Add(time.Hour*24)),
362+
CreatedAt: takeFirst(orig.CreatedAt, time.Now()),
363+
UpdatedAt: takeFirst(orig.UpdatedAt, time.Now()),
364+
})
365+
366+
require.NoError(t, err, "insert git auth link")
367+
return link
368+
}
369+
343370
func TemplateVersion(t *testing.T, db database.Store, orig database.TemplateVersion) database.TemplateVersion {
344371
version, err := db.InsertTemplateVersion(context.Background(), database.InsertTemplateVersionParams{
345372
ID: takeFirst(orig.ID, uuid.New()),

coderd/database/dbgen/generator_test.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,16 @@ func TestGenerator(t *testing.T) {
4444
require.Equal(t, exp, must(db.GetUserLinkByLinkedID(context.Background(), exp.LinkedID)))
4545
})
4646

47+
t.Run("GitAuthLink", func(t *testing.T) {
48+
t.Parallel()
49+
db := dbfake.New()
50+
exp := dbgen.GitAuthLink(t, db, database.GitAuthLink{})
51+
require.Equal(t, exp, must(db.GetGitAuthLink(context.Background(), database.GetGitAuthLinkParams{
52+
ProviderID: exp.ProviderID,
53+
UserID: exp.UserID,
54+
})))
55+
})
56+
4757
t.Run("WorkspaceResource", func(t *testing.T) {
4858
t.Parallel()
4959
db := dbfake.New()
@@ -166,6 +176,13 @@ func TestGenerator(t *testing.T) {
166176
exp := dbgen.User(t, db, database.User{})
167177
require.Equal(t, exp, must(db.GetUserByID(context.Background(), exp.ID)))
168178
})
179+
180+
t.Run("SSHKey", func(t *testing.T) {
181+
t.Parallel()
182+
db := dbfake.New()
183+
exp := dbgen.GitSSHKey(t, db, database.GitSSHKey{})
184+
require.Equal(t, exp, must(db.GetGitSSHKey(context.Background(), exp.UserID)))
185+
})
169186
}
170187

171188
func must[T any](value T, err error) T {

0 commit comments

Comments
 (0)