github.com/gitbundle/modules@v0.0.0-20231025071548-85b91c5c3b01/git/repo_ref_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 "path/filepath" 10 "testing" 11 12 "github.com/stretchr/testify/assert" 13 ) 14 15 func TestRepository_GetRefs(t *testing.T) { 16 bareRepo1Path := filepath.Join(testReposDir, "repo1_bare") 17 bareRepo1, err := openRepositoryWithDefaultContext(bareRepo1Path) 18 assert.NoError(t, err) 19 defer bareRepo1.Close() 20 21 refs, err := bareRepo1.GetRefs() 22 23 assert.NoError(t, err) 24 assert.Len(t, refs, 5) 25 26 expectedRefs := []string{ 27 BranchPrefix + "branch1", 28 BranchPrefix + "branch2", 29 BranchPrefix + "master", 30 TagPrefix + "test", 31 NotesRef, 32 } 33 34 for _, ref := range refs { 35 assert.Contains(t, expectedRefs, ref.Name) 36 } 37 } 38 39 func TestRepository_GetRefsFiltered(t *testing.T) { 40 bareRepo1Path := filepath.Join(testReposDir, "repo1_bare") 41 bareRepo1, err := openRepositoryWithDefaultContext(bareRepo1Path) 42 assert.NoError(t, err) 43 defer bareRepo1.Close() 44 45 refs, err := bareRepo1.GetRefsFiltered(TagPrefix) 46 47 assert.NoError(t, err) 48 if assert.Len(t, refs, 1) { 49 assert.Equal(t, TagPrefix+"test", refs[0].Name) 50 assert.Equal(t, "tag", refs[0].Type) 51 assert.Equal(t, "3ad28a9149a2864384548f3d17ed7f38014c9e8a", refs[0].Object.String()) 52 } 53 }