code.gitea.io/gitea@v1.22.3/modules/git/repo_test.go (about) 1 // Copyright 2017 The Gitea Authors. All rights reserved. 2 // SPDX-License-Identifier: MIT 3 4 package git 5 6 import ( 7 "context" 8 "path/filepath" 9 "testing" 10 11 "github.com/stretchr/testify/assert" 12 ) 13 14 func TestGetLatestCommitTime(t *testing.T) { 15 bareRepo1Path := filepath.Join(testReposDir, "repo1_bare") 16 lct, err := GetLatestCommitTime(DefaultContext, bareRepo1Path) 17 assert.NoError(t, err) 18 // Time is Sun Nov 13 16:40:14 2022 +0100 19 // which is the time of commit 20 // ce064814f4a0d337b333e646ece456cd39fab612 (refs/heads/master) 21 assert.EqualValues(t, 1668354014, lct.Unix()) 22 } 23 24 func TestRepoIsEmpty(t *testing.T) { 25 emptyRepo2Path := filepath.Join(testReposDir, "repo2_empty") 26 repo, err := openRepositoryWithDefaultContext(emptyRepo2Path) 27 assert.NoError(t, err) 28 defer repo.Close() 29 isEmpty, err := repo.IsEmpty() 30 assert.NoError(t, err) 31 assert.True(t, isEmpty) 32 } 33 34 func TestRepoGetDivergingCommits(t *testing.T) { 35 bareRepo1Path := filepath.Join(testReposDir, "repo1_bare") 36 do, err := GetDivergingCommits(context.Background(), bareRepo1Path, "master", "branch2") 37 assert.NoError(t, err) 38 assert.Equal(t, DivergeObject{ 39 Ahead: 1, 40 Behind: 5, 41 }, do) 42 43 do, err = GetDivergingCommits(context.Background(), bareRepo1Path, "master", "master") 44 assert.NoError(t, err) 45 assert.Equal(t, DivergeObject{ 46 Ahead: 0, 47 Behind: 0, 48 }, do) 49 50 do, err = GetDivergingCommits(context.Background(), bareRepo1Path, "master", "test") 51 assert.NoError(t, err) 52 assert.Equal(t, DivergeObject{ 53 Ahead: 0, 54 Behind: 2, 55 }, do) 56 }