This repository was archived by the owner on Feb 17, 2022. It is now read-only.
Repository navigation
Expand file tree
/
Copy pathmain_test.go
More file actions
206 lines (171 loc) · 4.63 KB
/
Copy pathmain_test.go
File metadata and controls
206 lines (171 loc) · 4.63 KB
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
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
package main_test
import (
"os"
"os/exec"
"path/filepath"
"strings"
"time"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
"github.com/onsi/gomega/gbytes"
"github.com/onsi/gomega/gexec"
. "github.com/zapatacomputing/git-import"
)
var _ = Describe("Main", func() {
var (
url string
dir string
branch string
tag string
pathToCMD string
session *gexec.Session
command *exec.Cmd
err error
)
BeforeEach(func() {
pathToCMD, err = gexec.Build("github.com/zapatacomputing/git-import")
Expect(err).ShouldNot(HaveOccurred())
})
AfterEach(func() {
curPath, err := os.Getwd()
Expect(err).ShouldNot(HaveOccurred())
os.RemoveAll(filepath.Join(curPath, dir))
})
Context("with all the arguments passed correctly", func() {
BeforeEach(func() {
url = "git@github.com:zapatacomputing/test.git"
dir = "test"
branch = "master"
tag = ""
command = exec.Command(pathToCMD, "-url", url, "-dir", dir, "-branch", branch, "-tag", tag)
})
It("should exit successfully", func() {
session, err = gexec.Start(command, GinkgoWriter, GinkgoWriter)
Expect(err).ShouldNot(HaveOccurred())
time.Sleep(10 * time.Second)
Expect(session).Should(gexec.Exit())
Expect(session.Out).Should(gbytes.Say(`.*Enumerating objects*.`))
Expect(session.Out).Should(gbytes.Say(`.*Counting objects*.`))
Expect(session.Out).Should(gbytes.Say(`.*Compressing objects*.`))
Expect(session.Out).Should(gbytes.Say(`.*Total*.`))
})
})
Context("with a missing url", func() {
BeforeEach(func() {
url = ""
dir = "test"
branch = "master"
tag = ""
command = exec.Command(pathToCMD, "-url", url, "-dir", dir, "-branch", branch, "-tag", tag)
})
It("should fail", func() {
session, err = gexec.Start(command, GinkgoWriter, GinkgoWriter)
Expect(err).ShouldNot(HaveOccurred())
time.Sleep(2 * time.Second)
Expect(session).Should(gexec.Exit(1))
})
})
})
var _ = Describe("Clone", func() {
var url string
var dir string
var branch string
var tag string
var expectedFilePath string
var err error
BeforeEach(func() {
url = "git@github.com:zapatacomputing/test.git"
dir = "test"
branch = ""
tag = ""
curPath, err := os.Getwd()
Expect(err).ShouldNot(HaveOccurred())
expectedFilePath = filepath.Join(curPath, dir, "README.md")
})
AfterEach(func() {
curPath, err := os.Getwd()
Expect(err).ShouldNot(HaveOccurred())
os.RemoveAll(filepath.Join(curPath, dir))
})
Context("with a valid public repo, valid path and filled branch and and empty tag", func() {
BeforeEach(func() {
branch = "master"
})
AfterEach(func() {
branch = ""
})
It("should succeed", func() {
err = Clone(url, dir, branch, tag)
Expect(err).ShouldNot(HaveOccurred())
_, err := os.Stat(expectedFilePath)
Expect(err).ShouldNot(HaveOccurred())
})
})
Context("with a valid public repo, valid path and filled branch and filled tag", func() {
BeforeEach(func() {
branch = "master"
tag = "v1.0.0"
})
AfterEach(func() {
branch = ""
tag = ""
})
It("should fail", func() {
err = Clone(url, dir, branch, tag)
Expect(err).Should(HaveOccurred())
Expect(strings.ToLower(err.Error())).Should(ContainSubstring("please specify only the branch or only the tag"))
_, err := os.Stat(expectedFilePath)
Expect(err).Should(HaveOccurred())
})
})
Context("with a valid public repo, valid path and empty branch and empty tag", func() {
It("should fail", func() {
err = Clone(url, dir, branch, tag)
Expect(err).Should(HaveOccurred())
_, err := os.Stat(expectedFilePath)
Expect(err).Should(HaveOccurred())
})
})
Context("with a valid public repo, valid path and an invalid tag", func() {
BeforeEach(func() {
tag = "vnon-existent"
})
AfterEach(func() {
tag = ""
})
It("should fail", func() {
err = Clone(url, dir, branch, tag)
Expect(err).Should(HaveOccurred())
_, err := os.Stat(expectedFilePath)
Expect(err).Should(HaveOccurred())
})
})
Context("with a valid public repo, valid path and an invalid branch", func() {
BeforeEach(func() {
branch = "#$%#"
})
AfterEach(func() {
branch = ""
})
It("should fail", func() {
err = Clone(url, dir, branch, tag)
Expect(err).Should(HaveOccurred())
_, err := os.Stat(expectedFilePath)
Expect(err).Should(HaveOccurred())
})
})
Context("with a valid public repo, invalid path", func() {
BeforeEach(func() {
dir = ""
})
AfterEach(func() {
dir = "test"
})
It("should fail", func() {
err = Clone(url, dir, branch, tag)
Expect(err).Should(HaveOccurred())
_, err := os.Stat(expectedFilePath)
Expect(err).Should(HaveOccurred())
})
})
})