forked from KevinSnyderCodes/github-deployment-resource
-
Notifications
You must be signed in to change notification settings - Fork 0
/
out_command_test.go
146 lines (125 loc) · 4.48 KB
/
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
package resource_test
import (
"io/ioutil"
"time"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
"github.com/shipt/go-github/v32/github"
resource "github.com/linkyard/github-deployment-resource"
"github.com/linkyard/github-deployment-resource/fakes"
)
var _ = Describe("Status Out Command", func() {
var (
command *resource.OutCommand
githubClient *fakes.FakeGitHub
sourcesDir string
request resource.OutRequest
)
BeforeEach(func() {
githubClient = &fakes.FakeGitHub{}
command = resource.NewOutCommand(githubClient, ioutil.Discard)
})
buildDeployment := func(id int64, env string, task string) *github.Deployment {
return &github.Deployment{
ID: github.Int64(id),
Environment: github.String(env),
Task: github.String(task),
Ref: github.String("master"),
SHA: github.String("12345"),
Description: github.String("One more"),
Creator: &github.User{
Login: github.String("Something"),
},
CreatedAt: &github.Timestamp{time.Date(2016, 01, 20, 15, 15, 15, 0, time.UTC)},
}
}
buildDeploymentStatus := func(ID int64, state string) *github.DeploymentStatus {
return &github.DeploymentStatus{
ID: github.Int64(ID),
State: github.String(state),
CreatedAt: &github.Timestamp{time.Date(2016, 01, 20, 20, 20, 20, 0, time.UTC)},
}
}
Context("when creating a new deployment status", func() {
BeforeEach(func() {
githubClient.GetDeploymentReturns(buildDeployment(1234, "production", "deploy"), nil)
githubClient.ListDeploymentStatusesReturns([]*github.DeploymentStatus{
buildDeploymentStatus(12, "success"),
}, nil)
githubClient.CreateDeploymentStatusReturns(&github.DeploymentStatus{
ID: github.Int64(12),
State: github.String("success"),
CreatedAt: &github.Timestamp{time.Date(2016, 01, 20, 20, 20, 20, 0, time.UTC)},
}, nil)
})
Context("with strings in params", func() {
BeforeEach(func() {
request = resource.OutRequest{
Params: resource.OutParams{
ID: github.String("1234"),
State: github.String("success"),
LogURL: github.String("http://foo.com"),
},
}
})
It("creates a new status", func() {
_, err := command.Run(sourcesDir, request)
Ω(err).ShouldNot(HaveOccurred())
Ω(githubClient.CreateDeploymentStatusCallCount()).Should(Equal(1))
id, status := githubClient.CreateDeploymentStatusArgsForCall(0)
Ω(id).Should(Equal(*github.Int64(1234)))
Ω(status.State).Should(Equal(github.String("success")))
Ω(status.LogURL).Should(Equal(github.String("http://foo.com")))
})
It("returns some metadata", func() {
outResponse, err := command.Run(sourcesDir, request)
Ω(err).ShouldNot(HaveOccurred())
Ω(outResponse.Metadata).Should(ConsistOf(
resource.MetadataPair{Name: "id", Value: "1234"},
resource.MetadataPair{Name: "ref", Value: "master"},
resource.MetadataPair{Name: "sha", Value: "12345"},
resource.MetadataPair{Name: "task", Value: "deploy"},
resource.MetadataPair{Name: "environment", Value: "production"},
resource.MetadataPair{Name: "description", Value: "One more"},
resource.MetadataPair{Name: "creator", Value: "Something"},
resource.MetadataPair{Name: "status", Value: "success"},
resource.MetadataPair{Name: "status_id", Value: "12"},
resource.MetadataPair{Name: "created_at", Value: "2016-01-20 15:15:15"},
resource.MetadataPair{Name: "status_created_at", Value: "2016-01-20 20:20:20"},
resource.MetadataPair{Name: "status_count", Value: "1"},
))
})
It("returns the version number of the deployment, not the status", func() {
outResponse, err := command.Run(sourcesDir, request)
Ω(err).ShouldNot(HaveOccurred())
Ω(outResponse.Version).Should(Equal(
resource.Version{
ID: "1234",
Statuses: "success",
},
))
})
})
Context("when a required param is missing", func() {
BeforeEach(func() {
request = resource.OutRequest{
Params: resource.OutParams{},
}
})
It("id missing returns appropriate error", func() {
_, err := command.Run(sourcesDir, resource.OutRequest{
Params: resource.OutParams{},
})
Ω(err).Should(MatchError("id is a required parameter"))
})
It("state missing returns appropriate error", func() {
_, err := command.Run(sourcesDir, resource.OutRequest{
Params: resource.OutParams{
ID: github.String("1"),
},
})
Ω(err).Should(MatchError("state is a required parameter"))
})
})
})
})