MCPcopy Index your code
hub / github.com/rilldata/rill / testManagedGitRepos

Function testManagedGitRepos

admin/database/postgres/postgres_test.go:577–689  ·  view source on GitHub ↗
(t *testing.T, db database.DB)

Source from the content-addressed store, hash-verified

575}
576
577func testManagedGitRepos(t *testing.T, db database.DB) {
578 // create a user with random email id
579 user, err := db.InsertUser(context.Background(), &database.InsertUserOptions{Email: fmt.Sprintf("user%d@rilldata.com", time.Now().UnixNano())})
580 require.NoError(t, err)
581
582 // add some orgs
583 org1, err := db.InsertOrganization(context.Background(), &database.InsertOrganizationOptions{
584 Name: "test-mgd-repo-1",
585 CreatedByUserID: &user.ID,
586 })
587 require.NoError(t, err)
588
589 org2, err := db.InsertOrganization(context.Background(), &database.InsertOrganizationOptions{
590 Name: "test-mgd-repo-2",
591 CreatedByUserID: &user.ID,
592 })
593 require.NoError(t, err)
594
595 org3, err := db.InsertOrganization(context.Background(), &database.InsertOrganizationOptions{
596 Name: "test-mgd-repo-3",
597 CreatedByUserID: &user.ID,
598 })
599 require.NoError(t, err)
600
601 // insert some repos
602 m1, err := db.InsertManagedGitRepo(context.Background(), &database.InsertManagedGitRepoOptions{
603 OrgID: org1.ID,
604 Remote: "https://github.com/rilldata/rill.git",
605 OwnerID: user.ID,
606 })
607 require.NoError(t, err)
608
609 m2, err := db.InsertManagedGitRepo(context.Background(), &database.InsertManagedGitRepoOptions{
610 OrgID: org2.ID,
611 Remote: "https://github.com/rilldata/rill2.git",
612 OwnerID: user.ID,
613 })
614 require.NoError(t, err)
615
616 // there are no unused repos because just created
617 mgdRepos, err := db.FindUnusedManagedGitRepos(context.Background(), 100)
618 require.NoError(t, err)
619 require.Equal(t, 0, len(mgdRepos))
620
621 m3, err := db.InsertManagedGitRepo(context.Background(), &database.InsertManagedGitRepoOptions{
622 OrgID: org3.ID,
623 Remote: "https://github.com/rilldata/rill3.git",
624 OwnerID: user.ID,
625 })
626 require.NoError(t, err)
627
628 // create projects using the repos
629 p1, err := db.InsertProject(context.Background(), &database.InsertProjectOptions{
630 OrganizationID: org1.ID,
631 Name: "test-mgd-repo-1",
632 ManagedGitRepoID: &m1.ID,
633 })
634 require.NoError(t, err)

Callers 1

TestPostgresFunction · 0.85

Calls 12

InsertUserMethod · 0.65
InsertOrganizationMethod · 0.65
InsertManagedGitRepoMethod · 0.65
InsertProjectMethod · 0.65
CountManagedGitReposMethod · 0.65
DeleteProjectMethod · 0.65
DeleteOrganizationMethod · 0.65
FindManagedGitRepoMethod · 0.65
ExecMethod · 0.65
DeleteUserMethod · 0.65
DeleteManagedGitReposMethod · 0.65

Tested by

no test coverage detected