-
Notifications
You must be signed in to change notification settings - Fork 0
/
show_test.go
123 lines (100 loc) · 4.19 KB
/
show_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
package git_test
import (
"testing"
"time"
git "github.com/purpleclay/gitz"
"github.com/purpleclay/gitz/gittest"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestShowBlobs(t *testing.T) {
gittest.InitRepository(t)
gittest.TempFile(t, "README.md", "The quick brown fox jumps over the lazy dog")
gittest.StageFile(t, "README.md")
gittest.TempFile(t, "LICENSE", "Follow the yellow brick road")
gittest.StageFile(t, "LICENSE")
gittest.Commit(t, "docs: include readme")
// Lookup refs
readmeRef := gittest.ObjectRef(t, "README.md")
licenseRef := gittest.ObjectRef(t, "LICENSE")
client, _ := git.NewClient()
blobs, err := client.ShowBlobs(readmeRef, licenseRef)
require.NoError(t, err)
require.Len(t, blobs, 2)
assert.Equal(t, readmeRef, blobs[readmeRef].Ref)
assert.Equal(t, "The quick brown fox jumps over the lazy dog", blobs[readmeRef].Diff)
assert.Equal(t, licenseRef, blobs[licenseRef].Ref)
assert.Equal(t, "Follow the yellow brick road", blobs[licenseRef].Diff)
}
func TestShowTrees(t *testing.T) {
gittest.InitRepository(t, gittest.WithStagedFiles(
"README.md",
"pkg/scan/scanner.go",
"pkg/scan/scanner_test.go",
"internal/task/scan.go",
"internal/task.go",
"internal/tui/dashboard.go"))
gittest.Commit(t, "chore: commit everything")
// Lookup refs
pkgRef := gittest.ObjectRef(t, "pkg")
internalRef := gittest.ObjectRef(t, "internal")
client, _ := git.NewClient()
trees, err := client.ShowTrees(pkgRef, internalRef)
require.NoError(t, err)
require.Len(t, trees, 2)
assert.Equal(t, pkgRef, trees[pkgRef].Ref)
assert.ElementsMatch(t, []string{"scan/"}, trees[pkgRef].Entries)
assert.Equal(t, internalRef, trees[internalRef].Ref)
assert.ElementsMatch(t, []string{"task.go", "task/", "tui/"}, trees[internalRef].Entries)
}
func TestShowCommits(t *testing.T) {
gittest.InitRepository(t)
gittest.CommitEmptyWithAuthor(t, "joker", "joker@dc.com", "docs: document new parsing features")
gittest.CommitEmpty(t, `feat: add functionality to parse a commit
ensure a commit can be parsed when using the git show command`)
entries := gittest.Log(t)
client, _ := git.NewClient()
commits, err := client.ShowCommits(entries[0].Hash, entries[1].Hash)
require.NoError(t, err)
require.Len(t, commits, 2)
ref := entries[0].Hash
assert.Equal(t, ref, commits[ref].Ref)
assert.Equal(t, "batman", commits[ref].Author.Name)
assert.Equal(t, "batman@dc.com", commits[ref].Author.Email)
assert.WithinDuration(t, time.Now(), commits[ref].AuthorDate, time.Second*2)
assert.Equal(t, "batman", commits[ref].Committer.Name)
assert.Equal(t, "batman@dc.com", commits[ref].Committer.Email)
assert.WithinDuration(t, time.Now(), commits[ref].CommitterDate, time.Second*2)
assert.Equal(t, `feat: add functionality to parse a commit
ensure a commit can be parsed when using the git show command`, commits[ref].Message)
ref = entries[1].Hash
assert.Equal(t, ref, commits[ref].Ref)
assert.Equal(t, "joker", commits[ref].Author.Name)
assert.Equal(t, "joker@dc.com", commits[ref].Author.Email)
assert.WithinDuration(t, time.Now(), commits[ref].AuthorDate, time.Second*2)
assert.Equal(t, "batman", commits[ref].Committer.Name)
assert.Equal(t, "batman@dc.com", commits[ref].Committer.Email)
assert.WithinDuration(t, time.Now(), commits[ref].CommitterDate, time.Second*2)
assert.Equal(t, "docs: document new parsing features", commits[ref].Message)
}
func TestShowTags(t *testing.T) {
gittest.InitRepository(t)
gittest.Tag(t, "0.1.0")
gittest.TagAnnotated(t, "0.2.0", "chore: tagged release at 0.2.0")
client, _ := git.NewClient()
tags, err := client.ShowTags("0.1.0", "0.2.0")
require.NoError(t, err)
require.Len(t, tags, 2)
tag := tags["0.1.0"]
assert.Equal(t, "0.1.0", tag.Ref)
assert.Nil(t, tag.Annotation)
assert.Equal(t, gittest.InitialCommit, tag.Commit.Message)
tag = tags["0.2.0"]
assert.Equal(t, "0.2.0", tag.Ref)
require.NotNil(t, tag.Annotation)
assert.Equal(t, "batman", tag.Annotation.Tagger.Name)
assert.Equal(t, "batman@dc.com", tag.Annotation.Tagger.Email)
assert.WithinDuration(t, time.Now(), tag.Annotation.TaggerDate, time.Second*2)
assert.Equal(t, "chore: tagged release at 0.2.0", tag.Annotation.Message)
assert.Equal(t, gittest.InitialCommit, tag.Commit.Message)
}