This repository has been archived by the owner on Feb 9, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcheck_test.go
89 lines (69 loc) · 1.68 KB
/
check_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
package resource_test
import (
"bytes"
"encoding/json"
"os/exec"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
resource "github.com/cappyzawa/romver-resource"
)
var _ = Describe("Check", func() {
var req struct {
Source resource.Source
Version *resource.Version
}
var res []resource.Version
BeforeEach(func() {
req.Source = resource.Source{}
req.Version = &resource.Version{}
res = []resource.Version{}
})
JustBeforeEach(func() {
cmd := exec.Command(bins.Check)
payload, err := json.Marshal(req)
Expect(err).ToNot(HaveOccurred())
checkBuf := new(bytes.Buffer)
cmd.Stdin = bytes.NewBuffer(payload)
cmd.Stdout = checkBuf
cmd.Stderr = GinkgoWriter
err = cmd.Run()
Expect(err).ToNot(HaveOccurred())
err = json.Unmarshal(checkBuf.Bytes(), &res)
Expect(err).ToNot(HaveOccurred())
})
Context("when target file exists in github", func() {
BeforeEach(func() {
req.Source = resource.Source{
Driver: "git",
InitialVersion: "0",
URI: githubURI,
Branch: githubBranch,
Username: githubUsername,
Password: githubPassword,
File: "version",
}
})
It("works", func() {
Expect(len(res)).NotTo(BeZero())
})
})
Context("when target file does not exists in github", func() {
BeforeEach(func() {
req.Source = resource.Source{
Driver: "git",
InitialVersion: "0",
URI: githubURI,
Branch: githubBranch,
Username: githubUsername,
Password: githubPassword,
File: "missingFile",
}
})
It("works", func() {
Expect(len(res)).NotTo(BeZero())
})
It("response is initialVersion", func() {
Expect(res[0].Number).To(Equal(req.Source.InitialVersion))
})
})
})