forked from buildpacks/pack
-
Notifications
You must be signed in to change notification settings - Fork 0
/
git_test.go
104 lines (83 loc) · 2.4 KB
/
git_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
package registry_test
import (
"bytes"
"io/ioutil"
"os"
"path/filepath"
"testing"
"github.com/sclevine/spec"
"github.com/sclevine/spec/report"
"gopkg.in/src-d/go-git.v4"
"github.com/buildpacks/pack/internal/registry"
"github.com/buildpacks/pack/pkg/logging"
h "github.com/buildpacks/pack/testhelpers"
)
func TestGit(t *testing.T) {
spec.Run(t, "Git", testGit, spec.Parallel(), spec.Report(report.Terminal{}))
}
func testGit(t *testing.T, when spec.G, it spec.S) {
var (
registryCache registry.Cache
tmpDir string
err error
registryFixture string
outBuf bytes.Buffer
logger logging.Logger
username = "supra08"
)
it.Before(func() {
logger = logging.NewLogWithWriters(&outBuf, &outBuf)
tmpDir, err = ioutil.TempDir("", "registry")
h.AssertNil(t, err)
registryFixture = h.CreateRegistryFixture(t, tmpDir, filepath.Join("..", "..", "testdata", "registry"))
registryCache, err = registry.NewRegistryCache(logger, tmpDir, registryFixture)
h.AssertNil(t, err)
})
it.After(func() {
h.AssertNil(t, os.RemoveAll(tmpDir))
})
when("#GitCommit", func() {
when("ADD buildpack", func() {
it("commits addition", func() {
err := registry.GitCommit(registry.Buildpack{
Namespace: "example",
Name: "python",
Version: "1.0.0",
Yanked: false,
Address: "example.com",
}, username, registryCache)
h.AssertNil(t, err)
repo, err := git.PlainOpen(registryCache.Root)
h.AssertNil(t, err)
head, err := repo.Head()
h.AssertNil(t, err)
cIter, err := repo.Log(&git.LogOptions{From: head.Hash()})
h.AssertNil(t, err)
commit, err := cIter.Next()
h.AssertNil(t, err)
h.AssertEq(t, commit.Message, "ADD example/python@1.0.0")
})
})
when("YANK buildpack", func() {
it("commits yank", func() {
err := registry.GitCommit(registry.Buildpack{
Namespace: "example",
Name: "python",
Version: "1.0.0",
Yanked: true,
Address: "example.com",
}, username, registryCache)
h.AssertNil(t, err)
repo, err := git.PlainOpen(registryCache.Root)
h.AssertNil(t, err)
head, err := repo.Head()
h.AssertNil(t, err)
cIter, err := repo.Log(&git.LogOptions{From: head.Hash()})
h.AssertNil(t, err)
commit, err := cIter.Next()
h.AssertNil(t, err)
h.AssertEq(t, commit.Message, "YANK example/python@1.0.0")
})
})
})
}