(t *testing.T, db database.DB)
| 575 | } |
| 576 | |
| 577 | func 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) |
no test coverage detected