gitea源码

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. // Copyright 2019 The Gitea Authors. All rights reserved.
  2. // SPDX-License-Identifier: MIT
  3. package git
  4. import (
  5. "path/filepath"
  6. "testing"
  7. "github.com/stretchr/testify/assert"
  8. )
  9. func TestGetNotes(t *testing.T) {
  10. bareRepo1Path := filepath.Join(testReposDir, "repo1_bare")
  11. bareRepo1, err := OpenRepository(t.Context(), bareRepo1Path)
  12. assert.NoError(t, err)
  13. defer bareRepo1.Close()
  14. note := Note{}
  15. err = GetNote(t.Context(), bareRepo1, "95bb4d39648ee7e325106df01a621c530863a653", &note)
  16. assert.NoError(t, err)
  17. assert.Equal(t, []byte("Note contents\n"), note.Message)
  18. assert.Equal(t, "Vladimir Panteleev", note.Commit.Author.Name)
  19. }
  20. func TestGetNestedNotes(t *testing.T) {
  21. repoPath := filepath.Join(testReposDir, "repo3_notes")
  22. repo, err := OpenRepository(t.Context(), repoPath)
  23. assert.NoError(t, err)
  24. defer repo.Close()
  25. note := Note{}
  26. err = GetNote(t.Context(), repo, "3e668dbfac39cbc80a9ff9c61eb565d944453ba4", &note)
  27. assert.NoError(t, err)
  28. assert.Equal(t, []byte("Note 2"), note.Message)
  29. err = GetNote(t.Context(), repo, "ba0a96fa63532d6c5087ecef070b0250ed72fa47", &note)
  30. assert.NoError(t, err)
  31. assert.Equal(t, []byte("Note 1"), note.Message)
  32. }
  33. func TestGetNonExistentNotes(t *testing.T) {
  34. bareRepo1Path := filepath.Join(testReposDir, "repo1_bare")
  35. bareRepo1, err := OpenRepository(t.Context(), bareRepo1Path)
  36. assert.NoError(t, err)
  37. defer bareRepo1.Close()
  38. note := Note{}
  39. err = GetNote(t.Context(), bareRepo1, "non_existent_sha", &note)
  40. assert.Error(t, err)
  41. assert.IsType(t, ErrNotExist{}, err)
  42. }