Skip to content

Commit

Permalink
add test
Browse files Browse the repository at this point in the history
  • Loading branch information
CaiCandong committed Aug 25, 2023
1 parent 4191603 commit 53cc3d5
Showing 1 changed file with 24 additions and 5 deletions.
29 changes: 24 additions & 5 deletions routers/private/hook_verification_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,41 @@
package private

import (
"code.gitea.io/gitea/models/unittest"
"context"
"testing"

"code.gitea.io/gitea/models/unittest"
"code.gitea.io/gitea/modules/git"

"github.com/stretchr/testify/assert"
)

var (
testReposDir = "tests/repos/"
)

func TestVerifyCommits(t *testing.T) {
unittest.PrepareTestEnv(t)

gitRepo, err := git.OpenRepository(context.Background(), ".")
gitRepo, err := git.OpenRepository(context.Background(), testReposDir+"repo1_hook_verification")
assert.NoError(t, err)
defer gitRepo.Close()

err = verifyCommits(git.EmptySHA, "9c5c60143975a120bf70ac4aed34bf903ef19db6", gitRepo, nil)
assert.NoError(t, err)
testCases := []struct {
base, head string
verified bool
}{
{"7d92f8f0cf7b989acf2c56a9a4387f5b39a92c41", "64e643f86a640d97f95820b43aeb28631042c629", true},
{git.EmptySHA, "451c1608ab9c5277fdc73ea68aea711c046ac7ac", true}, // New branch with verified commit
{"e05ec071e40a53cd4785345a99fd12f5dbb6a777", "7d92f8f0cf7b989acf2c56a9a4387f5b39a92c41", false},
{git.EmptySHA, "1128cd8e82948ea10b4932b2481210610604ce7e", false}, // New branch with unverified commit
}

for _, tc := range testCases {
err = verifyCommits(tc.base, tc.head, gitRepo, nil)
if tc.verified {
assert.NoError(t, err)
} else {
assert.Error(t, err)
}
}
}

0 comments on commit 53cc3d5

Please sign in to comment.