code.gitea.io/gitea@v1.19.3/modules/git/notes_test.go (about)

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