1// Copyright 2018 The Gitea Authors. All rights reserved.
2// Use of this source code is governed by a MIT-style
3// license that can be found in the LICENSE file.
4
5package git
6
7import (
8	"path/filepath"
9	"testing"
10
11	"github.com/stretchr/testify/assert"
12)
13
14func TestRepository_GetRefs(t *testing.T) {
15	bareRepo1Path := filepath.Join(testReposDir, "repo1_bare")
16	bareRepo1, err := OpenRepository(bareRepo1Path)
17	assert.NoError(t, err)
18	defer bareRepo1.Close()
19
20	refs, err := bareRepo1.GetRefs()
21
22	assert.NoError(t, err)
23	assert.Len(t, refs, 5)
24
25	expectedRefs := []string{
26		BranchPrefix + "branch1",
27		BranchPrefix + "branch2",
28		BranchPrefix + "master",
29		TagPrefix + "test",
30		NotesRef,
31	}
32
33	for _, ref := range refs {
34		assert.Contains(t, expectedRefs, ref.Name)
35	}
36}
37
38func TestRepository_GetRefsFiltered(t *testing.T) {
39	bareRepo1Path := filepath.Join(testReposDir, "repo1_bare")
40	bareRepo1, err := OpenRepository(bareRepo1Path)
41	assert.NoError(t, err)
42	defer bareRepo1.Close()
43
44	refs, err := bareRepo1.GetRefsFiltered(TagPrefix)
45
46	assert.NoError(t, err)
47	if assert.Len(t, refs, 1) {
48		assert.Equal(t, TagPrefix+"test", refs[0].Name)
49		assert.Equal(t, "tag", refs[0].Type)
50		assert.Equal(t, "3ad28a9149a2864384548f3d17ed7f38014c9e8a", refs[0].Object.String())
51	}
52}
53