@@ -5,37 +5,40 @@ import (
5
5
"github.com/aclevername/concourse-flake-detector/api/clientfake"
6
6
"github.com/aclevername/concourse-flake-detector/historybuilder"
7
7
8
+ "errors"
9
+ "fmt"
8
10
. "github.com/onsi/ginkgo"
9
11
. "github.com/onsi/gomega"
10
12
)
11
13
12
- var _ = Describe ("historybuilder" , func () {
13
- Describe ("GetJobHistory" , func () {
14
- It ("gets a history of the job" , func () {
15
- client := new (clientfake.FakeClient )
16
- testJob := api.Job {Name : "test-job" , URL : "/teams/main/pipelines/main/jobs/fly" }
17
-
18
- buildList := `[{"status":"succeeded","api_url":"/api/v1/builds/1"},{"status":"failed","api_url":"/api/v1/builds/2"}]`
19
- client .GetReturnsOnCall (0 , []byte (buildList ), nil )
20
-
21
- resources := `
14
+ const gitResourcewithVersion = `
22
15
{
23
16
"inputs": [
24
17
{
25
18
"name": "concourse",
26
19
"resource": "concourse",
27
20
"type": "git",
28
21
"version": {
29
- "ref": "d70a2b36579c7ea397d895ce7371f8cc9e044fc7 "
22
+ "ref": "%s "
30
23
},
31
24
"pipeline_id": 1
32
25
}
33
26
]
34
27
}
35
28
`
36
- client .GetReturnsOnCall (1 , []byte (resources ), nil )
37
29
38
- client .GetReturnsOnCall (2 , []byte (resources ), nil )
30
+ var _ = Describe ("historybuilder" , func () {
31
+ Describe ("GetJobHistory" , func () {
32
+ It ("gets a history of the job" , func () {
33
+ client := new (clientfake.FakeClient )
34
+ testJob := api.Job {Name : "test-job" , URL : "/teams/main/pipelines/main/jobs/fly" }
35
+
36
+ buildList := `[{"status":"succeeded","api_url":"/api/v1/builds/1"},{"status":"failed","api_url":"/api/v1/builds/2"}]`
37
+ client .GetReturnsOnCall (0 , []byte (buildList ), nil )
38
+
39
+ client .GetReturnsOnCall (1 , []byte (fmt .Sprintf (gitResourcewithVersion , "version1" )), nil )
40
+
41
+ client .GetReturnsOnCall (2 , []byte (fmt .Sprintf (gitResourcewithVersion , "version1" )), nil )
39
42
40
43
history , err := historybuilder .GetJobHistory (client , testJob )
41
44
@@ -51,7 +54,7 @@ var _ = Describe("historybuilder", func() {
51
54
Resource : "concourse" ,
52
55
Type : "git" ,
53
56
Version : historybuilder.Ref {
54
- Ref : "d70a2b36579c7ea397d895ce7371f8cc9e044fc7 " ,
57
+ Ref : "version1 " ,
55
58
},
56
59
PipelineID : 1 ,
57
60
}))
@@ -62,10 +65,36 @@ var _ = Describe("historybuilder", func() {
62
65
Resource : "concourse" ,
63
66
Type : "git" ,
64
67
Version : historybuilder.Ref {
65
- Ref : "d70a2b36579c7ea397d895ce7371f8cc9e044fc7 " ,
68
+ Ref : "version1 " ,
66
69
},
67
70
PipelineID : 1 ,
68
71
}))
69
72
})
73
+
74
+ Context ("when getting the job builds fails" , func () {
75
+ It ("returns an error" , func () {
76
+ client := new (clientfake.FakeClient )
77
+ testJob := api.Job {Name : "test-job" , URL : "/teams/main/pipelines/main/jobs/fly" }
78
+
79
+ buildList := `[{"status":"succeeded","api_url":"/api/v1/builds/1"},{"status":"failed","api_url":"/api/v1/builds/2"}]`
80
+ client .GetReturnsOnCall (0 , []byte (buildList ), nil )
81
+ client .GetReturnsOnCall (1 , []byte {}, errors .New ("failed" ))
82
+
83
+ _ , err := historybuilder .GetJobHistory (client , testJob )
84
+ Expect (err ).To (MatchError ("failed" ))
85
+ })
86
+ })
87
+
88
+ Context ("when getting the a builds resources fails" , func () {
89
+ It ("returns an error" , func () {
90
+ client := new (clientfake.FakeClient )
91
+ testJob := api.Job {Name : "test-job" , URL : "/teams/main/pipelines/main/jobs/fly" }
92
+
93
+ client .GetReturnsOnCall (0 , []byte {}, errors .New ("failed" ))
94
+
95
+ _ , err := historybuilder .GetJobHistory (client , testJob )
96
+ Expect (err ).To (MatchError ("failed" ))
97
+ })
98
+ })
70
99
})
71
100
})
0 commit comments