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.

notes_test.go 1.6KB

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