-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathget_resource_versions_test.go
131 lines (111 loc) · 3.64 KB
/
get_resource_versions_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
package main
import (
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
"io/ioutil"
"github.com/concourse/concourse/atc"
"github.com/concourse/concourse/go-concourse/concourse"
"github.com/concourse/concourse/go-concourse/concourse/concoursefakes"
yaml "gopkg.in/yaml.v2"
)
var _ = Describe("GetResourceVersions", func() {
var teamName = "main"
var pipelineName = "control-tower"
var jobName = "minor"
var buildName = "1"
var expectedStruct map[string]atc.Version
var client *concoursefakes.FakeClient
BeforeEach(func() {
expectedStruct = map[string]atc.Version{}
expectedBytes, err := ioutil.ReadFile("./fixtures/expected_output.yml")
Ω(err).ShouldNot(HaveOccurred())
Ω(expectedBytes).ShouldNot(BeEmpty())
err = yaml.Unmarshal(expectedBytes, expectedStruct)
Ω(err).ShouldNot(HaveOccurred())
fakeTeam := new(concoursefakes.FakeTeam)
fakeTeam.JobBuildStub = func(pipeline atc.PipelineRef, job, build string) (atc.Build, bool, error) {
if pipeline.Name == "control-tower" && job == "minor" && build == "1" {
return atc.Build{ID: 2098}, true, nil
}
return atc.Build{}, false, nil
}
wrongTeam := new(concoursefakes.FakeTeam)
wrongTeam.JobBuildStub = func(pipeline atc.PipelineRef, job, build string) (atc.Build, bool, error) {
return atc.Build{}, false, nil
}
client = new(concoursefakes.FakeClient)
client.TeamStub = func(teamName string) concourse.Team {
if teamName == "main" {
return fakeTeam
}
return wrongTeam
}
client.BuildResourcesStub = func(buildID int) (atc.BuildInputsOutputs, bool, error) {
if buildID == 2098 {
return atc.BuildInputsOutputs{
Inputs: []atc.PublicBuildInput{
{
Name: "control-tower-ops",
Version: atc.Version{
"commit": "407f8ab92a7258cbae32d1ad987b64f8d18a9a3a",
"ref": "0.0.8",
},
},
{
Name: "pcf-ops",
Version: atc.Version{
"digest": "sha256:8a4f9f1647080c224f015cc655146fda7329baa8c7b279b597dee114a69ff97a",
},
},
{
Name: "version",
Version: atc.Version{
"number": "0.2.0",
},
},
{
Name: "control-tower",
Version: atc.Version{
"ref": "244a2df8b612d8e9b560ba73023d7673b5d4d007",
},
},
},
}, true, nil
}
return atc.BuildInputsOutputs{}, false, nil
}
})
It("returns the expected stuff", func() {
resourceVersions, err := GetResourceVersions(client, teamName, pipelineName, jobName, buildName)
Ω(err).ShouldNot(HaveOccurred())
Ω(resourceVersions).Should(Equal(expectedStruct))
})
Context("when the team does not exist", func() {
It("returns an error", func() {
resourceVersions, err := GetResourceVersions(client, "does-not-exist", pipelineName, jobName, buildName)
Ω(err).Should(HaveOccurred())
Ω(resourceVersions).Should(BeNil())
})
})
Context("when the pipeline does not exist", func() {
It("returns an error", func() {
resourceVersions, err := GetResourceVersions(client, teamName, "does-not-exist", jobName, buildName)
Ω(err).Should(HaveOccurred())
Ω(resourceVersions).Should(BeNil())
})
})
Context("when the job does not exist", func() {
It("returns an error", func() {
resourceVersions, err := GetResourceVersions(client, teamName, pipelineName, "does-not-exist", buildName)
Ω(err).Should(HaveOccurred())
Ω(resourceVersions).Should(BeNil())
})
})
Context("when the build does not exist", func() {
It("returns an error", func() {
resourceVersions, err := GetResourceVersions(client, teamName, pipelineName, jobName, "does-not-exist")
Ω(err).Should(HaveOccurred())
Ω(resourceVersions).Should(BeNil())
})
})
})