You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

hook_verification_test.go 1.1KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. // Copyright 2023 The Gitea Authors. All rights reserved.
  2. // SPDX-License-Identifier: MIT
  3. package private
  4. import (
  5. "context"
  6. "testing"
  7. "code.gitea.io/gitea/models/unittest"
  8. "code.gitea.io/gitea/modules/git"
  9. "github.com/stretchr/testify/assert"
  10. )
  11. var testReposDir = "tests/repos/"
  12. func TestVerifyCommits(t *testing.T) {
  13. unittest.PrepareTestEnv(t)
  14. gitRepo, err := git.OpenRepository(context.Background(), testReposDir+"repo1_hook_verification")
  15. defer gitRepo.Close()
  16. assert.NoError(t, err)
  17. testCases := []struct {
  18. base, head string
  19. verified bool
  20. }{
  21. {"72920278f2f999e3005801e5d5b8ab8139d3641c", "d766f2917716d45be24bfa968b8409544941be32", true},
  22. {git.EmptySHA, "93eac826f6188f34646cea81bf426aa5ba7d3bfe", true}, // New branch with verified commit
  23. {"9779d17a04f1e2640583d35703c62460b2d86e0a", "72920278f2f999e3005801e5d5b8ab8139d3641c", false},
  24. {git.EmptySHA, "9ce3f779ae33f31fce17fac3c512047b75d7498b", false}, // New branch with unverified commit
  25. }
  26. for _, tc := range testCases {
  27. err = verifyCommits(tc.base, tc.head, gitRepo, nil)
  28. if tc.verified {
  29. assert.NoError(t, err)
  30. } else {
  31. assert.Error(t, err)
  32. }
  33. }
  34. }