@@ -40,13 +40,87 @@ func TestDisableRunner(t *testing.T) {
40
40
}
41
41
}
42
42
43
+ func stringToTime (date string , t * testing.T ) * time.Time {
44
+ d , err := time .Parse (timeLayout , date )
45
+ if err != nil {
46
+ t .Errorf ("Unable to parse date [%s]: %v" , d , err )
47
+ }
48
+ return & d
49
+ }
50
+
51
+ func expectedRunnerJobs (t * testing.T ) []* Job {
52
+ pipeline := struct {
53
+ ID int `json:"id"`
54
+ Ref string `json:"ref"`
55
+ Sha string `json:"sha"`
56
+ Status string `json:"status"`
57
+ }{
58
+ ID : 8777 ,
59
+ Ref : "master" ,
60
+ Sha : "6c016b801a88f4bd31f927fc045b5c746a6f823e" ,
61
+ Status : "failed" ,
62
+ }
63
+
64
+ return []* Job {
65
+ & Job {
66
+ ID : 1 ,
67
+ Status : "failed" ,
68
+ Stage : "test" ,
69
+ Name : "run_tests" ,
70
+ Ref : "master" ,
71
+ Tag : false ,
72
+ Coverage : 0 ,
73
+ AllowFailure : false ,
74
+ CreatedAt : stringToTime ("2021-10-22T11:59:25.201Z" , t ),
75
+ StartedAt : stringToTime ("2021-10-22T11:59:33.660Z" , t ),
76
+ FinishedAt : stringToTime ("2021-10-22T15:59:25.201Z" , t ),
77
+ Duration : 171.540594 ,
78
+ QueuedDuration : 2.535766 ,
79
+ User : & User {
80
+ ID : 368 ,
81
+ Name : "John SMITH" ,
82
+ Username : "john.smith" ,
83
+ AvatarURL : "https://gitlab.example.com/uploads/-/system/user/avatar/368/avatar.png" ,
84
+ State : "blocked" ,
85
+ WebURL : "https://gitlab.example.com/john.smith" ,
86
+
87
+ },
88
+ Commit : & Commit {
89
+ ID : "6c016b801a88f4bd31f927fc045b5c746a6f823e" ,
90
+ ShortID : "6c016b80" ,
91
+ CreatedAt : stringToTime ("2018-03-21T14:41:00.000+01:00" , t ),
92
+ ParentIDs : []string {"6008b4902d40799ab11688e502d9f1f27f6d2e18" },
93
+ Title : "Update env for specific runner" ,
94
+ Message : "Update env for specific runner\n " ,
95
+ AuthorName : "John SMITH" ,
96
+
97
+ AuthoredDate : stringToTime ("2018-03-21T14:41:00.000+01:00" , t ),
98
+ CommitterName : "John SMITH" ,
99
+ CommitterEmail :
"[email protected] " ,
100
+ CommittedDate : stringToTime ("2018-03-21T14:41:00.000+01:00" , t ),
101
+ WebURL : "https://gitlab.example.com/awesome/packages/common/-/commit/6c016b801a88f4bd31f927fc045b5c746a6f823e" ,
102
+ },
103
+ Pipeline : pipeline ,
104
+ WebURL : "https://gitlab.example.com/awesome/packages/common/-/jobs/14606" ,
105
+ Project : & Project {
106
+ ID : 3252 ,
107
+ Description : "Common nodejs paquet for producer" ,
108
+ Name : "common" ,
109
+ NameWithNamespace : "awesome" ,
110
+ Path : "common" ,
111
+ PathWithNamespace : "awesome" ,
112
+ CreatedAt : stringToTime ("2018-02-13T09:21:48.107Z" , t ),
113
+ },
114
+ },
115
+ }
116
+ }
43
117
func TestListRunnersJobs (t * testing.T ) {
44
118
mux , server , client := setup (t )
45
119
defer teardown (server )
46
120
47
121
mux .HandleFunc ("/api/v4/runners/1/jobs" , func (w http.ResponseWriter , r * http.Request ) {
48
122
testMethod (t , r , http .MethodGet )
49
- fmt .Fprint (w , `[{"id":1},{"id":2}]` )
123
+ fmt .Fprint (w , exampleListRunnerJobs )
50
124
})
51
125
52
126
opt := & ListRunnerJobsOptions {}
@@ -56,7 +130,7 @@ func TestListRunnersJobs(t *testing.T) {
56
130
t .Fatalf ("Runners.ListRunnersJobs returns an error: %v" , err )
57
131
}
58
132
59
- want := [] * Job {{ ID : 1 }, { ID : 2 }}
133
+ want := expectedRunnerJobs ( t )
60
134
if ! reflect .DeepEqual (want , jobs ) {
61
135
t .Errorf ("Runners.ListRunnersJobs returned %+v, want %+v" , jobs , want )
62
136
}
0 commit comments