This repository has been archived by the owner on May 13, 2024. It is now read-only.
forked from ahume/github-deployment-resource
-
Notifications
You must be signed in to change notification settings - Fork 0
/
deployment_out_command_test.go
163 lines (138 loc) · 5.07 KB
/
deployment_out_command_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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
package resource_test
import (
"io/ioutil"
"os"
"time"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
"github.com/google/go-github/v28/github"
resource "github.com/3DHubs/github-deployment-resource"
"github.com/3DHubs/github-deployment-resource/fakes"
)
var _ = Describe("Deployment Out Command", func() {
var (
command *resource.DeploymentOutCommand
githubClient *fakes.FakeGitHub
sourcesDir string
request resource.OutRequest
)
BeforeEach(func() {
var err error
githubClient = &fakes.FakeGitHub{}
command = resource.NewDeploymentOutCommand(githubClient, ioutil.Discard)
sourcesDir, err = ioutil.TempDir("", "github-deployment")
Ω(err).ShouldNot(HaveOccurred())
})
AfterEach(func() {
Ω(os.RemoveAll(sourcesDir)).Should(Succeed())
})
Context("when creating a new deployment", func() {
Context("with strings in params", func() {
Context("when all possible params are present", func() {
BeforeEach(func() {
githubClient.CreateDeploymentReturns(&github.Deployment{
ID: github.Int64(1),
Ref: github.String("ref"),
SHA: github.String("1234"),
Task: github.String("task"),
Description: github.String("desc"),
Environment: github.String("env"),
Creator: &github.User{
Login: github.String("theboss"),
},
CreatedAt: &github.Timestamp{time.Date(2016, 01, 20, 15, 15, 15, 0, time.UTC)},
}, nil)
request = resource.OutRequest{
Params: resource.OutParams{
Ref: github.String("ref"),
Task: github.String("task"),
Description: github.String("desc"),
Payload: &map[string]interface{}{
"one": "two",
},
Environment: github.String("env"),
AutoMerge: github.Bool(false),
},
}
})
It("creates a new deployment", func() {
_, err := command.Run(sourcesDir, request)
Ω(err).ShouldNot(HaveOccurred())
Ω(githubClient.CreateDeploymentCallCount()).Should(Equal(1))
deployment := githubClient.CreateDeploymentArgsForCall(0)
Ω(deployment.Ref).Should(Equal(github.String("ref")))
Ω(deployment.Task).Should(Equal(github.String("task")))
Ω(deployment.Description).Should(Equal(github.String("desc")))
Ω(deployment.Payload).Should(Equal(github.String(`{"concourse_payload":{"atc_external_url":"","build_id":"","build_job_name":"","build_name":"","build_pipeline_name":"","build_team_name":"","build_url":"/teams//pipelines//jobs//builds/"},"one":"two"}`)))
Ω(deployment.Environment).Should(Equal(github.String("env")))
Ω(deployment.AutoMerge).Should(Equal(github.Bool(false)))
})
It("returns some metadata", func() {
outResponse, err := command.Run(sourcesDir, request)
Ω(err).ShouldNot(HaveOccurred())
Ω(outResponse.Metadata).Should(ConsistOf(
resource.MetadataPair{Name: "id", Value: "1"},
resource.MetadataPair{Name: "ref", Value: "ref"},
resource.MetadataPair{Name: "sha", Value: "1234"},
resource.MetadataPair{Name: "task", Value: "task"},
resource.MetadataPair{Name: "environment", Value: "env"},
resource.MetadataPair{Name: "description", Value: "desc"},
resource.MetadataPair{Name: "creator", Value: "theboss"},
resource.MetadataPair{Name: "created_at", Value: "2016-01-20 15:15:15"},
resource.MetadataPair{Name: "status_count", Value: "0"},
))
})
It("returns the new version number", func() {
outResponse, err := command.Run(sourcesDir, request)
Ω(err).ShouldNot(HaveOccurred())
Ω(outResponse.Version).Should(Equal(
resource.Version{
ID: "1",
},
))
})
})
Context("when only required params are present", func() {
BeforeEach(func() {
githubClient.CreateDeploymentReturns(&github.Deployment{
ID: github.Int64(1),
Ref: github.String("ref"),
SHA: github.String("1234"),
Creator: &github.User{
Login: github.String("theboss"),
},
CreatedAt: &github.Timestamp{time.Date(2016, 01, 20, 15, 15, 15, 0, time.UTC)},
}, nil)
request = resource.OutRequest{
Params: resource.OutParams{
Ref: github.String("ref"),
},
}
})
It("returns some metadata", func() {
outResponse, err := command.Run(sourcesDir, request)
Ω(err).ShouldNot(HaveOccurred())
Ω(outResponse.Metadata).Should(ConsistOf(
resource.MetadataPair{Name: "id", Value: "1"},
resource.MetadataPair{Name: "ref", Value: "ref"},
resource.MetadataPair{Name: "sha", Value: "1234"},
resource.MetadataPair{Name: "creator", Value: "theboss"},
resource.MetadataPair{Name: "created_at", Value: "2016-01-20 15:15:15"},
resource.MetadataPair{Name: "status_count", Value: "0"},
))
})
})
Context("when required param ref is missing", func() {
BeforeEach(func() {
request = resource.OutRequest{
Params: resource.OutParams{},
}
})
It("returns appropriate error", func() {
_, err := command.Run(sourcesDir, request)
Ω(err).Should(MatchError("ref is a required parameter"))
})
})
})
})
})