s
This commit is contained in:
@@ -0,0 +1,76 @@
|
||||
package gitcmd
|
||||
|
||||
import (
|
||||
"context"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestListTags(t *testing.T) {
|
||||
f := newFixture(t)
|
||||
ts, err := f.repo.ListTags()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if len(ts) != 2 {
|
||||
t.Fatalf("len = %d, want 2", len(ts))
|
||||
}
|
||||
|
||||
byName := map[string]Tag{}
|
||||
for _, tg := range ts {
|
||||
byName[tg.Name] = tg
|
||||
}
|
||||
|
||||
v1, ok := byName["v1.0"]
|
||||
if !ok {
|
||||
t.Fatal("missing tag v1.0")
|
||||
}
|
||||
if !v1.IsAnnotated {
|
||||
t.Error("v1.0 IsAnnotated = false, want true")
|
||||
}
|
||||
if v1.Tagger != aliceName {
|
||||
t.Errorf("v1.0 Tagger = %q, want Alice", v1.Tagger)
|
||||
}
|
||||
if v1.Message != "release v1.0" {
|
||||
t.Errorf("v1.0 Message = %q, want 'release v1.0'", v1.Message)
|
||||
}
|
||||
if len(v1.SHA) != 40 {
|
||||
t.Errorf("v1.0 SHA len = %d, want 40 (tag object)", len(v1.SHA))
|
||||
}
|
||||
if len(v1.ShortSHA) < 7 {
|
||||
t.Errorf("v1.0 ShortSHA = %q, want >=7 chars", v1.ShortSHA)
|
||||
}
|
||||
|
||||
v09, ok := byName["v0.9"]
|
||||
if !ok {
|
||||
t.Fatal("missing tag v0.9")
|
||||
}
|
||||
if v09.IsAnnotated {
|
||||
t.Error("v0.9 IsAnnotated = true, want false")
|
||||
}
|
||||
if v09.Tagger != "" {
|
||||
t.Errorf("v0.9 Tagger = %q, want empty (lightweight)", v09.Tagger)
|
||||
}
|
||||
if v09.SHA != f.c2 {
|
||||
t.Errorf("v0.9 SHA = %q, want commit SHA %q", v09.SHA, f.c2)
|
||||
}
|
||||
if !v09.TagDate.IsZero() {
|
||||
t.Errorf("v0.9 TagDate = %v, want zero (lightweight)", v09.TagDate)
|
||||
}
|
||||
}
|
||||
|
||||
func TestListTagsEmptyRepo(t *testing.T) {
|
||||
dir := t.TempDir()
|
||||
bare := dir + "/empty.git"
|
||||
gitRun(t, "", nil, "init", "-q", "--bare", bare)
|
||||
r, err := OpenRepository(context.Background(), bare)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
ts, err := r.ListTags()
|
||||
if err != nil {
|
||||
t.Fatalf("ListTags on empty repo: %v", err)
|
||||
}
|
||||
if len(ts) != 0 {
|
||||
t.Errorf("empty repo tags = %d, want 0", len(ts))
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user