diff options
Diffstat (limited to 'internal/db/repos_test.go')
-rw-r--r-- | internal/db/repos_test.go | 52 |
1 files changed, 40 insertions, 12 deletions
diff --git a/internal/db/repos_test.go b/internal/db/repos_test.go index 0f7617de..99c19505 100644 --- a/internal/db/repos_test.go +++ b/internal/db/repos_test.go @@ -20,7 +20,6 @@ func TestRepos(t *testing.T) { if testing.Short() { t.Skip() } - t.Parallel() tables := []interface{}{new(Repository)} @@ -32,8 +31,9 @@ func TestRepos(t *testing.T) { name string test func(*testing.T, *repos) }{ - {"create", reposCreate}, + {"Create", reposCreate}, {"GetByName", reposGetByName}, + {"Touch", reposTouch}, } { t.Run(tc.name, func(t *testing.T) { t.Cleanup(func() { @@ -52,9 +52,9 @@ func reposCreate(t *testing.T, db *repos) { ctx := context.Background() t.Run("name not allowed", func(t *testing.T) { - _, err := db.create(ctx, + _, err := db.Create(ctx, 1, - createRepoOpts{ + CreateRepoOptions{ Name: "my.git", }, ) @@ -63,15 +63,15 @@ func reposCreate(t *testing.T, db *repos) { }) t.Run("already exists", func(t *testing.T) { - _, err := db.create(ctx, 2, - createRepoOpts{ + _, err := db.Create(ctx, 2, + CreateRepoOptions{ Name: "repo1", }, ) require.NoError(t, err) - _, err = db.create(ctx, 2, - createRepoOpts{ + _, err = db.Create(ctx, 2, + CreateRepoOptions{ Name: "repo1", }, ) @@ -79,8 +79,8 @@ func reposCreate(t *testing.T, db *repos) { assert.Equal(t, wantErr, err) }) - repo, err := db.create(ctx, 3, - createRepoOpts{ + repo, err := db.Create(ctx, 3, + CreateRepoOptions{ Name: "repo2", }, ) @@ -94,8 +94,8 @@ func reposCreate(t *testing.T, db *repos) { func reposGetByName(t *testing.T, db *repos) { ctx := context.Background() - repo, err := db.create(ctx, 1, - createRepoOpts{ + repo, err := db.Create(ctx, 1, + CreateRepoOptions{ Name: "repo1", }, ) @@ -108,3 +108,31 @@ func reposGetByName(t *testing.T, db *repos) { wantErr := ErrRepoNotExist{args: errutil.Args{"ownerID": int64(1), "name": "bad_name"}} assert.Equal(t, wantErr, err) } + +func reposTouch(t *testing.T, db *repos) { + ctx := context.Background() + + repo, err := db.Create(ctx, 1, + CreateRepoOptions{ + Name: "repo1", + }, + ) + require.NoError(t, err) + + err = db.WithContext(ctx).Model(new(Repository)).Where("id = ?", repo.ID).Update("is_bare", true).Error + require.NoError(t, err) + + // Make sure it is bare + got, err := db.GetByName(ctx, repo.OwnerID, repo.Name) + require.NoError(t, err) + assert.True(t, got.IsBare) + + // Touch it + err = db.Touch(ctx, repo.ID) + require.NoError(t, err) + + // It should not be bare anymore + got, err = db.GetByName(ctx, repo.OwnerID, repo.Name) + require.NoError(t, err) + assert.False(t, got.IsBare) +} |