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
/
in_test.go
140 lines (111 loc) · 2.83 KB
/
in_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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
package resource_test
import (
"bytes"
"encoding/json"
"io/ioutil"
"os"
"os/exec"
"path/filepath"
"strconv"
"strings"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
resource "github.com/cappyzawa/romver-resource"
)
var _ = Describe("In", func() {
var desDir string
var req struct {
Source resource.Source
Version resource.Version
Params resource.InParams
}
var res struct {
Version resource.Version
Metadata resource.Metadata
}
BeforeEach(func() {
var err error
desDir, err = ioutil.TempDir("", "romver-resource-in-dir")
Expect(err).NotTo(HaveOccurred())
req.Source = resource.Source{}
req.Params = resource.InParams{}
res.Version = resource.Version{}
res.Metadata = resource.Metadata{}
})
AfterEach(func() {
Expect(os.RemoveAll(desDir)).To(Succeed())
})
JustBeforeEach(func() {
cmd := exec.Command(bins.In, desDir)
payload, err := json.Marshal(req)
Expect(err).ToNot(HaveOccurred())
inBuf := new(bytes.Buffer)
cmd.Stdin = bytes.NewBuffer(payload)
cmd.Stdout = inBuf
cmd.Stderr = GinkgoWriter
err = cmd.Run()
Expect(err).ToNot(HaveOccurred())
err = json.Unmarshal(inBuf.Bytes(), &res)
Expect(err).ToNot(HaveOccurred())
})
Context("no bump", func() {
BeforeEach(func() {
req.Source = resource.Source{
Driver: "git",
InitialVersion: "0",
URI: githubURI,
Branch: githubBranch,
Username: githubUsername,
Password: githubPassword,
File: "version",
}
req.Params = resource.InParams{
Bump: false,
}
req.Version = resource.Version{
Number: "111",
}
})
It("works", func() {
Expect(res.Version.Number).To(Equal(req.Version.Number))
})
It("the content of the version file is the request version number", func() {
b, err := ioutil.ReadFile(filepath.Join(desDir, "version"))
Expect(err).NotTo(HaveOccurred())
number := strings.TrimSpace(string(b))
Expect(number).To(Equal(req.Version.Number))
})
})
Context("bump", func() {
BeforeEach(func() {
req.Source = resource.Source{
Driver: "git",
InitialVersion: "0",
URI: githubURI,
Branch: githubBranch,
Username: githubUsername,
Password: githubPassword,
File: "version",
}
req.Params = resource.InParams{
Bump: true,
}
req.Version = resource.Version{
Number: "111",
}
})
It("works", func() {
Expect(res.Version.Number).To(Equal(req.Version.Number))
})
It("the content of the version file is the request version number + 1", func() {
b, err := ioutil.ReadFile(filepath.Join(desDir, "version"))
Expect(err).NotTo(HaveOccurred())
number := strings.TrimSpace(string(b))
reqVerInt, err := strconv.Atoi(req.Version.Number)
Expect(err).NotTo(HaveOccurred())
expectInt := reqVerInt + 1
expect := strconv.Itoa(expectInt)
Expect(number).To(Equal(expect))
})
})
})