|
4 | 4 | package private |
5 | 5 |
|
6 | 6 | import ( |
| 7 | + "code.gitea.io/gitea/models/unittest" |
7 | 8 | "context" |
8 | 9 | "testing" |
9 | 10 |
|
10 | | - "code.gitea.io/gitea/models/unittest" |
11 | 11 | "code.gitea.io/gitea/modules/git" |
12 | 12 |
|
13 | 13 | "github.com/stretchr/testify/assert" |
14 | 14 | ) |
15 | 15 |
|
| 16 | +var ( |
| 17 | + testReposDir = "tests/repos/" |
| 18 | +) |
| 19 | + |
16 | 20 | func TestVerifyCommits(t *testing.T) { |
17 | 21 | unittest.PrepareTestEnv(t) |
18 | 22 |
|
19 | | - gitRepo, err := git.OpenRepository(context.Background(), ".") |
| 23 | + gitRepo, err := git.OpenRepository(context.Background(), testReposDir+"repo1_hook_verification") |
20 | 24 | assert.NoError(t, err) |
21 | | - defer gitRepo.Close() |
22 | 25 |
|
23 | | - err = verifyCommits(git.EmptySHA, "9c5c60143975a120bf70ac4aed34bf903ef19db6", gitRepo, nil) |
24 | | - assert.NoError(t, err) |
| 26 | + testCases := []struct { |
| 27 | + base, head string |
| 28 | + verified bool |
| 29 | + }{ |
| 30 | + {"7d92f8f0cf7b989acf2c56a9a4387f5b39a92c41", "64e643f86a640d97f95820b43aeb28631042c629", true}, |
| 31 | + {git.EmptySHA, "451c1608ab9c5277fdc73ea68aea711c046ac7ac", true}, // New branch with verified commit |
| 32 | + {"e05ec071e40a53cd4785345a99fd12f5dbb6a777", "7d92f8f0cf7b989acf2c56a9a4387f5b39a92c41", false}, |
| 33 | + {git.EmptySHA, "1128cd8e82948ea10b4932b2481210610604ce7e", false}, // New branch with unverified commit |
| 34 | + } |
| 35 | + |
| 36 | + for _, tc := range testCases { |
| 37 | + err = verifyCommits(tc.base, tc.head, gitRepo, nil) |
| 38 | + if tc.verified { |
| 39 | + assert.NoError(t, err) |
| 40 | + } else { |
| 41 | + assert.Error(t, err) |
| 42 | + } |
| 43 | + } |
25 | 44 | } |
0 commit comments