github.com/gitbundle/modules@v0.0.0-20231025071548-85b91c5c3b01/git/notes_test.go (about)

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