-
Notifications
You must be signed in to change notification settings - Fork 128
/
repo_tag_test.go
156 lines (132 loc) · 3.29 KB
/
repo_tag_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
// Copyright 2020 The Gogs Authors. All rights reserved.
// Use of this source code is governed by a MIT-style
// license that can be found in the LICENSE file.
package git
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestRepository_Tag(t *testing.T) {
tests := []struct {
name string
opt TagOptions
expTag *Tag
}{
{
name: "v1.0.0",
expTag: &Tag{
typ: ObjectCommit,
id: MustIDFromString("0eedd79eba4394bbef888c804e899731644367fe"),
commitID: MustIDFromString("0eedd79eba4394bbef888c804e899731644367fe"),
refspec: "refs/tags/v1.0.0",
},
}, {
name: "v1.1.0",
expTag: &Tag{
typ: ObjectTag,
id: MustIDFromString("b39c8508bbc4b00ad2e24d358012ea123bcafd8d"),
commitID: MustIDFromString("0eedd79eba4394bbef888c804e899731644367fe"),
refspec: "refs/tags/v1.1.0",
},
},
}
for _, test := range tests {
t.Run("", func(t *testing.T) {
tag, err := testrepo.Tag(test.name, test.opt)
if err != nil {
t.Fatal(err)
}
assert.Equal(t, test.expTag.Type(), tag.Type())
assert.Equal(t, test.expTag.ID().String(), tag.ID().String())
assert.Equal(t, test.expTag.CommitID().String(), tag.CommitID().String())
assert.Equal(t, test.expTag.Refspec(), tag.Refspec())
})
}
}
func TestRepository_Tags(t *testing.T) {
// Make sure it does not blow up
tags, err := testrepo.Tags(TagsOptions{})
if err != nil {
t.Fatal(err)
}
assert.NotEmpty(t, tags)
}
func TestRepository_Tags_VersionSort(t *testing.T) {
r, cleanup, err := setupTempRepo()
if err != nil {
t.Fatal(err)
}
defer cleanup()
err = r.CreateTag("v3.0.0", "master")
if err != nil {
t.Fatal(err)
}
err = r.CreateTag("v2.999.0", "master")
if err != nil {
t.Fatal(err)
}
tags, err := r.Tags(TagsOptions{
SortKey: "-version:refname",
Pattern: "v*",
})
if err != nil {
t.Fatal(err)
}
if len(tags) < 2 {
t.Fatalf("Should have at least two tags but got %d", len(tags))
}
assert.Equal(t, "v3.0.0", tags[0])
assert.Equal(t, "v2.999.0", tags[1])
}
func TestRepository_CreateTag(t *testing.T) {
r, cleanup, err := setupTempRepo()
if err != nil {
t.Fatal(err)
}
defer cleanup()
assert.False(t, r.HasReference(RefsTags+"v2.0.0"))
err = r.CreateTag("v2.0.0", "master", CreateTagOptions{})
if err != nil {
t.Fatal(err)
}
assert.True(t, r.HasReference(RefsTags+"v2.0.0"))
}
func TestRepository_CreateAnnotatedTag(t *testing.T) {
r, cleanup, err := setupTempRepo()
if err != nil {
t.Fatal(err)
}
defer cleanup()
assert.False(t, r.HasReference(RefsTags+"v2.0.0"))
err = r.CreateTag("v2.0.0", "master", CreateTagOptions{
Annotated: true,
Author: &Signature{
Name: "alice",
Email: "[email protected]",
},
})
if err != nil {
t.Fatal(err)
}
assert.True(t, r.HasReference(RefsTags+"v2.0.0"))
tag, err := r.Tag("v2.0.0")
if err != nil {
t.Fatal(err)
}
assert.Equal(t, "alice", tag.tagger.Name)
assert.Equal(t, "[email protected]", tag.tagger.Email)
assert.False(t, tag.tagger.When.IsZero())
}
func TestRepository_DeleteTag(t *testing.T) {
r, cleanup, err := setupTempRepo()
if err != nil {
t.Fatal(err)
}
defer cleanup()
assert.True(t, r.HasReference(RefsTags+"v1.0.0"))
err = r.DeleteTag("v1.0.0", DeleteTagOptions{})
if err != nil {
t.Fatal(err)
}
assert.False(t, r.HasReference(RefsTags+"v1.0.0"))
}