types.rs 36.2 KB
Newer Older
1
2
3
4
5
6
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.

Ben Boeckel's avatar
Ben Boeckel committed
7
8
use std::fs::File;

Brad King's avatar
Brad King committed
9
use crates::chrono::{NaiveDate, TimeZone, Utc};
10
use crates::serde::de::DeserializeOwned;
11
use crates::serde_json::{from_reader, json};
12

13
use types::*;
14

15
fn read_test_file<T: DeserializeOwned>(name: &str) -> T {
Ben Boeckel's avatar
Ben Boeckel committed
16
17
18
19
20
    let fin = File::open(format!(
        concat!(env!("CARGO_MANIFEST_DIR"), "/data/{}.json"),
        name,
    ))
    .unwrap();
21
22
23
24
25

    from_reader::<File, T>(fin).unwrap()
}

#[test]
26
27
fn test_read_award_emoji() {
    let award_emoji: AwardEmoji = read_test_file("award_emoji");
28

29
30
31
    assert_eq!(award_emoji.id, AwardId::new(335));
    assert_eq!(award_emoji.name, "8ball");
    assert_eq!(award_emoji.user.username, "ben.boeckel");
Ben Boeckel's avatar
Ben Boeckel committed
32
33
34
35
    assert_eq!(
        award_emoji.user.web_url,
        "https://gitlab.kitware.com/ben.boeckel",
    );
36
37
    assert_eq!(award_emoji.user.name, "Ben Boeckel");
    assert_eq!(award_emoji.user.state, UserState::Active);
Ben Boeckel's avatar
Ben Boeckel committed
38
39
40
41
    assert_eq!(
        award_emoji.user.avatar_url,
        Some(
            "https://secure.gravatar.com/avatar/2f5f7e99190174edb5a2f66b8653b0b2?s=80&d=identicon"
42
                .into()
Ben Boeckel's avatar
Ben Boeckel committed
43
44
        ),
    );
45
    assert_eq!(award_emoji.user.id, UserId::new(13));
Ben Boeckel's avatar
Ben Boeckel committed
46
47
48
49
50
51
52
53
54
55
    assert_eq!(
        award_emoji.created_at,
        Utc.ymd(2016, 12, 7).and_hms_milli(16, 23, 46, 742),
    );
    assert_eq!(
        award_emoji.updated_at,
        Utc.ymd(2016, 12, 7).and_hms_milli(16, 23, 46, 742),
    );
    assert_eq!(
        award_emoji.awardable_id(),
56
        AwardableId::Note(NoteId::new(177_359)),
Ben Boeckel's avatar
Ben Boeckel committed
57
    );
58
59
60
61
62
63
64
65
66
67
68
69
    assert_eq!(award_emoji.awardable_type, AwardableType::Note);
}

#[test]
fn test_read_commit_note() {
    let commit_note: CommitNote = read_test_file("commit_note");

    assert_eq!(commit_note.note, "Example commit note for data fetching.");
    assert_eq!(commit_note.path, None);
    assert_eq!(commit_note.line, None);
    assert_eq!(commit_note.line_type, None);
    assert_eq!(commit_note.author.username, "ben.boeckel");
Ben Boeckel's avatar
Ben Boeckel committed
70
71
72
73
    assert_eq!(
        commit_note.author.web_url,
        "https://gitlab.kitware.com/ben.boeckel",
    );
74
75
    assert_eq!(commit_note.author.name, "Ben Boeckel");
    assert_eq!(commit_note.author.state, UserState::Active);
Ben Boeckel's avatar
Ben Boeckel committed
76
77
78
79
    assert_eq!(
        commit_note.author.avatar_url,
        Some(
            "https://secure.gravatar.com/avatar/2f5f7e99190174edb5a2f66b8653b0b2?s=80&d=identicon"
80
                .into()
Ben Boeckel's avatar
Ben Boeckel committed
81
82
        ),
    );
83
    assert_eq!(commit_note.author.id, UserId::new(13));
Ben Boeckel's avatar
Ben Boeckel committed
84
85
86
87
    assert_eq!(
        commit_note.created_at,
        Utc.ymd(2016, 12, 7).and_hms_milli(16, 28, 33, 966),
    );
88
89
90
91
92
93
}

#[test]
fn test_read_commit_status() {
    let commit_status: CommitStatus = read_test_file("commit_status");

94
    assert_eq!(commit_status.id, CommitStatusId::new(931_434));
Ben Boeckel's avatar
Ben Boeckel committed
95
96
    assert_eq!(
        commit_status.sha,
97
        ObjectId::new("de4ac3cf96cb8a0893be22b03f5171d934f9d392"),
Ben Boeckel's avatar
Ben Boeckel committed
98
    );
99
    assert_eq!(commit_status.ref_, Some("master".into()));
100
101
    assert_eq!(commit_status.status, StatusState::Success);
    assert_eq!(commit_status.name, "rust-gitlab-megas-linux-debug");
Ben Boeckel's avatar
Ben Boeckel committed
102
103
104
    assert_eq!(
        commit_status.target_url,
        Some(
105
            "https://buildbot.kitware.com/builders/rust-gitlab-megas-linux-debug/builds/41".into()
Ben Boeckel's avatar
Ben Boeckel committed
106
107
        ),
    );
108
    assert_eq!(commit_status.description, Some("expected".into()));
Ben Boeckel's avatar
Ben Boeckel committed
109
110
111
112
    assert_eq!(
        commit_status.created_at,
        Utc.ymd(2016, 11, 8).and_hms_milli(14, 35, 32, 627),
    );
113
    assert_eq!(commit_status.started_at, None);
Ben Boeckel's avatar
Ben Boeckel committed
114
115
116
117
    assert_eq!(
        commit_status.finished_at,
        Some(Utc.ymd(2016, 11, 8).and_hms_milli(14, 35, 32, 629)),
    );
118
119
    assert_eq!(commit_status.allow_failure, false);
    assert_eq!(commit_status.author.username, "buildbot");
Ben Boeckel's avatar
Ben Boeckel committed
120
121
122
123
    assert_eq!(
        commit_status.author.web_url,
        "https://gitlab.kitware.com/buildbot",
    );
124
125
    assert_eq!(commit_status.author.name, "buildbot");
    assert_eq!(commit_status.author.state, UserState::Active);
Ben Boeckel's avatar
Ben Boeckel committed
126
127
    assert_eq!(
        commit_status.author.avatar_url,
128
        Some("https://gitlab.kitware.com/uploads/-/system/user/avatar/35/buildbot-logo.png".into()),
Ben Boeckel's avatar
Ben Boeckel committed
129
    );
130
    assert_eq!(commit_status.author.id, UserId::new(35));
131
    assert_eq!(commit_status.coverage, None);
132
133
134
135
136
137
138
}

#[test]
fn test_read_issue() {
    let issue: Issue = read_test_file("issue");

    assert_eq!(issue.id, IssueId::new(69328));
Brad King's avatar
Brad King committed
139
    assert_eq!(issue.iid, IssueInternalId::new(6));
140
141
    assert_eq!(issue.project_id, ProjectId::new(855));
    assert_eq!(issue.title, "fix documentation warnings");
142
    assert_eq!(issue.description, Some("".into()));
143
    assert_eq!(issue.state, IssueState::Closed);
Ben Boeckel's avatar
Ben Boeckel committed
144
145
146
147
148
149
    assert_eq!(
        issue.created_at,
        Utc.ymd(2016, 10, 30).and_hms_milli(18, 54, 28, 954),
    );
    assert_eq!(
        issue.updated_at,
Brad King's avatar
Brad King committed
150
        Utc.ymd(2019, 7, 17).and_hms_milli(13, 53, 48, 869),
Ben Boeckel's avatar
Ben Boeckel committed
151
    );
Brad King's avatar
Brad King committed
152
    assert_eq!(issue.closed_at, None);
Brad King's avatar
Brad King committed
153
    assert!(issue.closed_by.is_none());
Brad King's avatar
Brad King committed
154
155
    assert_eq!(issue.labels.len(), 1);
    assert_eq!(issue.labels[0], "area:doc");
156
157
    assert!(issue.milestone.is_none());
    assert_eq!(issue.author.username, "ben.boeckel");
Ben Boeckel's avatar
Ben Boeckel committed
158
159
160
161
    assert_eq!(
        issue.author.web_url,
        "https://gitlab.kitware.com/ben.boeckel",
    );
162
163
    assert_eq!(issue.author.name, "Ben Boeckel");
    assert_eq!(issue.author.state, UserState::Active);
Ben Boeckel's avatar
Ben Boeckel committed
164
165
166
167
    assert_eq!(
        issue.author.avatar_url,
        Some(
            "https://secure.gravatar.com/avatar/2f5f7e99190174edb5a2f66b8653b0b2?s=80&d=identicon"
168
                .into()
Ben Boeckel's avatar
Ben Boeckel committed
169
170
        ),
    );
171
172
173
174
175
176
177
    assert_eq!(issue.author.id, UserId::new(13));
    if let Some(ref assignee) = issue.assignee {
        assert_eq!(assignee.username, "ben.boeckel");
        assert_eq!(assignee.web_url, "https://gitlab.kitware.com/ben.boeckel");
        assert_eq!(assignee.name, "Ben Boeckel");
        assert_eq!(assignee.state, UserState::Active);
        assert_eq!(assignee.avatar_url,
178
                   Some("https://secure.gravatar.com/avatar/2f5f7e99190174edb5a2f66b8653b0b2?s=80&d=identicon".into()));
179
180
181
182
        assert_eq!(assignee.id, UserId::new(13));
    } else {
        panic!("expected to have an assignee for the issue");
    }
Brad King's avatar
Brad King committed
183
184
185
186
187
188
189
190
    if let Some(ref assignees) = issue.assignees {
        assert_eq!(assignees.len(), 1);
        let assignee = &assignees[0];
        assert_eq!(assignee.username, "ben.boeckel");
        assert_eq!(assignee.web_url, "https://gitlab.kitware.com/ben.boeckel");
        assert_eq!(assignee.name, "Ben Boeckel");
        assert_eq!(assignee.state, UserState::Active);
        assert_eq!(assignee.avatar_url,
191
                   Some("https://secure.gravatar.com/avatar/2f5f7e99190174edb5a2f66b8653b0b2?s=80&d=identicon".into()));
Brad King's avatar
Brad King committed
192
193
194
195
196
        assert_eq!(assignee.id, UserId::new(13));
    } else {
        panic!("expected to have assignees for the issue");
    }
    assert_eq!(issue.subscribed, Some(true));
197
    assert_eq!(issue.user_notes_count, 0);
Brad King's avatar
Brad King committed
198
    assert_eq!(issue.merge_requests_count, 1);
199
200
201
    assert_eq!(issue.upvotes, 0);
    assert_eq!(issue.downvotes, 0);
    assert_eq!(issue.due_date, None);
Brad King's avatar
Brad King committed
202
    assert_eq!(issue.has_tasks, Some(false));
203
    assert_eq!(issue.confidential, false);
Brad King's avatar
Brad King committed
204
    assert_eq!(issue.discussion_locked, None);
Ben Boeckel's avatar
Ben Boeckel committed
205
206
207
208
    assert_eq!(
        issue.web_url,
        "https://gitlab.kitware.com/utils/rust-gitlab/issues/6",
    );
Brad King's avatar
Brad King committed
209
    assert!(issue.has_links());
210
211
212
213
214
215
216
217
}

#[test]
fn test_read_issue_reference() {
    let issue_reference: IssueReference = read_test_file("issue_reference");

    if let IssueReference::Internal(issue) = issue_reference {
        assert_eq!(issue.id, IssueId::new(69075));
Brad King's avatar
Brad King committed
218
        assert_eq!(issue.iid, IssueInternalId::new(5));
219
220
        assert_eq!(issue.project_id, ProjectId::new(855));
        assert_eq!(issue.title, "Add project hook APIs");
Ben Boeckel's avatar
Ben Boeckel committed
221
222
223
224
225
        assert_eq!(
            issue.description,
            Some(
                "The workflow currently requires that the robot be able to register itself as a \
                 webhook for new projects. An API needs added for this.\n\nCc: @brad.king"
226
                    .into()
Ben Boeckel's avatar
Ben Boeckel committed
227
228
            ),
        );
229
        assert_eq!(issue.state, IssueState::Closed);
Ben Boeckel's avatar
Ben Boeckel committed
230
231
232
233
234
235
236
237
        assert_eq!(
            issue.created_at,
            Utc.ymd(2016, 10, 4).and_hms_milli(18, 59, 37, 178),
        );
        assert_eq!(
            issue.updated_at,
            Utc.ymd(2017, 7, 7).and_hms_milli(6, 31, 5, 370),
        );
Brad King's avatar
Brad King committed
238
        assert_eq!(issue.closed_at, None);
Brad King's avatar
Brad King committed
239
        assert!(issue.closed_by.is_none());
240
241
242
        assert!(issue.labels.is_empty());
        assert!(issue.milestone.is_none());
        assert_eq!(issue.author.username, "ben.boeckel");
Ben Boeckel's avatar
Ben Boeckel committed
243
244
245
246
        assert_eq!(
            issue.author.web_url,
            "https://gitlab.kitware.com/ben.boeckel",
        );
247
248
249
        assert_eq!(issue.author.name, "Ben Boeckel");
        assert_eq!(issue.author.state, UserState::Active);
        assert_eq!(issue.author.avatar_url,
250
                   Some("https://secure.gravatar.com/avatar/2f5f7e99190174edb5a2f66b8653b0b2?s=80&d=identicon".into()));
251
252
253
254
255
256
257
        assert_eq!(issue.author.id, UserId::new(13));
        if let Some(ref assignee) = issue.assignee {
            assert_eq!(assignee.username, "ben.boeckel");
            assert_eq!(assignee.web_url, "https://gitlab.kitware.com/ben.boeckel");
            assert_eq!(assignee.name, "Ben Boeckel");
            assert_eq!(assignee.state, UserState::Active);
            assert_eq!(assignee.avatar_url,
258
                       Some("https://secure.gravatar.com/avatar/2f5f7e99190174edb5a2f66b8653b0b2?s=80&d=identicon".into()));
259
260
261
262
            assert_eq!(assignee.id, UserId::new(13));
        } else {
            panic!("expected to have an assignee for the issue");
        }
Brad King's avatar
Brad King committed
263
        assert_eq!(issue.subscribed, None);
Brad King's avatar
Brad King committed
264
265
266
267
        assert_eq!(issue.time_stats.time_estimate, 0);
        assert_eq!(issue.time_stats.total_time_spent, 0);
        assert_eq!(issue.time_stats.human_time_estimate, None);
        assert_eq!(issue.time_stats.human_total_time_spent, None);
268
        assert_eq!(issue.user_notes_count, 0);
Brad King's avatar
Brad King committed
269
        assert_eq!(issue.merge_requests_count, 1);
270
271
272
273
        assert_eq!(issue.upvotes, 0);
        assert_eq!(issue.downvotes, 0);
        assert_eq!(issue.due_date, None);
        assert_eq!(issue.confidential, false);
Brad King's avatar
Brad King committed
274
        assert_eq!(issue.discussion_locked, None);
Ben Boeckel's avatar
Ben Boeckel committed
275
276
277
278
        assert_eq!(
            issue.web_url,
            "https://gitlab.kitware.com/utils/rust-gitlab/issues/5",
        );
279
280
281
282
283
284
285
286
287
288
289
290
291
    } else {
        panic!("expected to have an internal issue reference");
    }
}

#[test]
fn test_read_member() {
    let member: Member = read_test_file("member");

    assert_eq!(member.username, "kwrobot");
    assert_eq!(member.name, "Kitware Robot");
    assert_eq!(member.id, UserId::new(11));
    assert_eq!(member.state, UserState::Active);
Ben Boeckel's avatar
Ben Boeckel committed
292
293
294
295
    assert_eq!(
        member.avatar_url,
        Some(
            "https://secure.gravatar.com/avatar/9ddcd45fcb89d966aab95b1f1002f84c?s=80&d=identicon"
296
                .into()
Ben Boeckel's avatar
Ben Boeckel committed
297
298
        ),
    );
299
300
301
302
303
304
305
306
307
    assert_eq!(member.web_url, "https://gitlab.kitware.com/kwrobot");
    assert_eq!(member.access_level, 50);
    assert_eq!(member.expires_at, None);
}

#[test]
fn test_read_merge_request() {
    let merge_request: MergeRequest = read_test_file("merge_request");

308
    assert_eq!(merge_request.id, MergeRequestId::new(20215));
Brad King's avatar
Brad King committed
309
    assert_eq!(merge_request.iid, MergeRequestInternalId::new(35));
310
    assert_eq!(merge_request.project_id, ProjectId::new(855));
311
    assert_eq!(merge_request.title, "gitlab: expose hook addition API");
312
    assert_eq!(merge_request.description, Some("Fixes #5.".into()));
313
    assert_eq!(merge_request.state, MergeRequestState::Merged);
Ben Boeckel's avatar
Ben Boeckel committed
314
315
316
317
318
319
320
321
322
323
324
325
    assert_eq!(
        merge_request.created_at,
        Utc.ymd(2016, 10, 4).and_hms_milli(19, 56, 43, 276),
    );
    assert_eq!(
        merge_request.updated_at,
        Utc.ymd(2016, 10, 4).and_hms_milli(20, 18, 57, 940),
    );
    assert_eq!(
        merge_request.merged_at,
        Some(Utc.ymd(2016, 10, 4).and_hms_milli(20, 18, 57, 914)),
    );
Brad King's avatar
Brad King committed
326
327
    assert!(merge_request.merged_by.is_none());
    assert!(merge_request.closed_by.is_none());
328
    assert_eq!(merge_request.target_branch, "master");
329
    assert_eq!(merge_request.source_branch, "add_hook-api");
330
331
    assert_eq!(merge_request.upvotes, 0);
    assert_eq!(merge_request.downvotes, 0);
332
    assert_eq!(merge_request.author.username, "ben.boeckel");
Ben Boeckel's avatar
Ben Boeckel committed
333
334
335
336
    assert_eq!(
        merge_request.author.web_url,
        "https://gitlab.kitware.com/ben.boeckel",
    );
337
    assert_eq!(merge_request.author.name, "Ben Boeckel");
338
    assert_eq!(merge_request.author.state, UserState::Active);
Ben Boeckel's avatar
Ben Boeckel committed
339
340
341
342
    assert_eq!(
        merge_request.author.avatar_url,
        Some(
            "https://secure.gravatar.com/avatar/2f5f7e99190174edb5a2f66b8653b0b2?s=80&d=identicon"
343
                .into()
Ben Boeckel's avatar
Ben Boeckel committed
344
345
        ),
    );
346
347
348
349
350
351
352
    assert_eq!(merge_request.author.id, UserId::new(13));
    if let Some(ref assignee) = merge_request.assignee {
        assert_eq!(assignee.username, "brad.king");
        assert_eq!(assignee.web_url, "https://gitlab.kitware.com/brad.king");
        assert_eq!(assignee.name, "Brad King");
        assert_eq!(assignee.state, UserState::Active);
        assert_eq!(assignee.avatar_url,
353
                   Some("https://secure.gravatar.com/avatar/0617392a2f9fd505720d0c42cefc1a10?s=80&d=identicon".into()));
354
355
356
357
        assert_eq!(assignee.id, UserId::new(10));
    } else {
        panic!("expected to have an assignee for the merge request");
    }
Brad King's avatar
Brad King committed
358
359
360
361
362
363
364
365
    if let Some(ref assignees) = merge_request.assignees {
        assert_eq!(assignees.len(), 1);
        let assignee = &assignees[0];
        assert_eq!(assignee.username, "brad.king");
        assert_eq!(assignee.web_url, "https://gitlab.kitware.com/brad.king");
        assert_eq!(assignee.name, "Brad King");
        assert_eq!(assignee.state, UserState::Active);
        assert_eq!(assignee.avatar_url,
366
                   Some("https://secure.gravatar.com/avatar/0617392a2f9fd505720d0c42cefc1a10?s=80&d=identicon".into()));
Brad King's avatar
Brad King committed
367
368
369
370
        assert_eq!(assignee.id, UserId::new(10));
    } else {
        panic!("expected to have assignees for the merge request");
    }
371
    assert_eq!(merge_request.source_project_id, ProjectId::new(856));
372
373
374
    assert_eq!(merge_request.target_project_id, ProjectId::new(855));
    assert!(merge_request.labels.is_empty());
    assert_eq!(merge_request.work_in_progress, false);
Brad King's avatar
Brad King committed
375
    assert!(merge_request.allow_collaboration.is_none());
Brad King's avatar
Brad King committed
376
    assert!(merge_request.allow_maintainer_to_push.is_none());
377
    assert!(merge_request.milestone.is_none());
Brad King's avatar
Brad King committed
378
    assert_eq!(merge_request.squash, false);
Brad King's avatar
Brad King committed
379
    assert_eq!(merge_request.merge_when_pipeline_succeeds, false);
380
    assert_eq!(merge_request.merge_status, MergeStatus::CanBeMerged);
Ben Boeckel's avatar
Ben Boeckel committed
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
    assert_eq!(
        merge_request.sha,
        Some(ObjectId::new("04e94ae667024a62a90179f395bfdc2b35f3efd2")),
    );
    assert_eq!(
        merge_request.diff_refs.as_ref().unwrap().base_sha,
        Some(ObjectId::new("981262b03fc0149c1677ca51ea47b570e30d6a90")),
    );
    assert_eq!(
        merge_request.diff_refs.as_ref().unwrap().head_sha,
        Some(ObjectId::new("04e94ae667024a62a90179f395bfdc2b35f3efd2")),
    );
    assert_eq!(
        merge_request.diff_refs.as_ref().unwrap().start_sha,
        Some(ObjectId::new("981262b03fc0149c1677ca51ea47b570e30d6a90")),
    );
Brad King's avatar
Brad King committed
397
398
    assert_eq!(merge_request.merge_error, None);
    assert_eq!(merge_request.rebase_in_progress, None);
399
    assert_eq!(merge_request.merge_commit_sha, None);
Brad King's avatar
Brad King committed
400
    assert_eq!(merge_request.subscribed, Some(true));
Brad King's avatar
Brad King committed
401
402
403
404
    assert_eq!(merge_request.time_stats.time_estimate, 0);
    assert_eq!(merge_request.time_stats.total_time_spent, 0);
    assert_eq!(merge_request.time_stats.human_time_estimate, None);
    assert_eq!(merge_request.time_stats.human_total_time_spent, None);
405
    assert_eq!(merge_request.changes_count, Some("3".into()));
406
    assert_eq!(merge_request.user_notes_count, 3);
Brad King's avatar
Brad King committed
407
    assert_eq!(merge_request.discussion_locked, None);
408
409
    assert_eq!(merge_request.should_remove_source_branch, None);
    assert_eq!(merge_request.force_remove_source_branch, Some(true));
410
    assert_eq!(merge_request.user.unwrap().can_merge, true);
Ben Boeckel's avatar
Ben Boeckel committed
411
412
413
414
    assert_eq!(
        merge_request.web_url,
        "https://gitlab.kitware.com/utils/rust-gitlab/merge_requests/35",
    );
415
416
417
418
419
420
}

#[test]
fn test_read_note() {
    let note: Note = read_test_file("note");

421
    assert_eq!(note.id, NoteId::new(177_373));
Ben Boeckel's avatar
Ben Boeckel committed
422
    assert_eq!(note.body, "Status changed to merged");
423
    assert_eq!(note.attachment, None);
Brad King's avatar
Brad King committed
424
425
426
    assert_eq!(note.author.username, "kwrobot");
    assert_eq!(note.author.web_url, "https://gitlab.kitware.com/kwrobot");
    assert_eq!(note.author.name, "Kitware Robot");
427
    assert_eq!(note.author.state, UserState::Active);
Ben Boeckel's avatar
Ben Boeckel committed
428
429
430
431
    assert_eq!(
        note.author.avatar_url,
        Some(
            "https://secure.gravatar.com/avatar/9ddcd45fcb89d966aab95b1f1002f84c?s=80&d=identicon"
432
                .into()
Ben Boeckel's avatar
Ben Boeckel committed
433
434
        ),
    );
Brad King's avatar
Brad King committed
435
    assert_eq!(note.author.id, UserId::new(11));
Ben Boeckel's avatar
Ben Boeckel committed
436
437
438
439
440
441
442
443
    assert_eq!(
        note.created_at,
        Utc.ymd(2016, 10, 4).and_hms_milli(20, 18, 57, 937),
    );
    assert_eq!(
        note.updated_at,
        Utc.ymd(2016, 10, 4).and_hms_milli(20, 18, 57, 937),
    );
Brad King's avatar
Brad King committed
444
445
446
    assert_eq!(note.resolvable, false);
    assert_eq!(note.resolved, None);
    assert!(note.resolved_by.is_none());
447
    assert_eq!(note.system, true);
Ben Boeckel's avatar
Ben Boeckel committed
448
449
450
451
452
453
454
455
456
457
    assert_eq!(
        note.noteable_id(),
        Some(NoteableId::MergeRequest(MergeRequestId::new(20215))),
    );
    assert_eq!(
        note.noteable_iid(),
        Some(NoteableInternalId::MergeRequest(
            MergeRequestInternalId::new(35)
        )),
    );
458
459
460
    assert_eq!(note.noteable_type, NoteType::MergeRequest);
}

461
462
463
#[test]
fn test_read_singlenote_discussion() {
    let discussions: Vec<Discussion> = read_test_file("discussion");
Ben Boeckel's avatar
Ben Boeckel committed
464
465
466
467
    let discussion = discussions
        .iter()
        .find(|x| x.id.value() == "18ea341cb10e952889e277836ba638c6b17ff26c")
        .unwrap();
468
469
470
471
472
473
474
475
476
477
478
    assert!(discussion.individual_note);
    assert_eq!(discussion.notes.len(), 1);
    let note = discussion.notes.get(0).unwrap();
    assert!(!(note.resolvable));
    assert!(note.position.is_none());
    assert!(note.note_type.is_none())
}

#[test]
fn test_read_nocode_discussion() {
    let discussions: Vec<Discussion> = read_test_file("discussion");
Ben Boeckel's avatar
Ben Boeckel committed
479
480
481
482
    let discussion = discussions
        .iter()
        .find(|x| x.id.value() == "a4d5505b3556eaa45edbe567af7aebc1760dedd7")
        .unwrap();
483
484
485
486
487
488
489
490
491
492
493
494
    assert!(!(discussion.individual_note));
    assert_eq!(discussion.notes.len(), 3);
    let question = discussion.notes.get(0).unwrap();
    let comment = discussion.notes.get(1).unwrap();
    assert!(question.resolvable);
    assert!(comment.resolvable);

    assert!(question.resolved.is_some());

    assert!(question.position.is_none());
    assert!(comment.position.is_none());

495
496
    assert_eq!(question.id, NoteId::new(607_911));
    assert_eq!(comment.id, NoteId::new(607_912));
497
498
499
500
501
502
503
504

    assert_eq!(question.note_type, Some(DiscussionNoteType::DiscussionNote));
    assert_eq!(comment.note_type, Some(DiscussionNoteType::DiscussionNote));
}

#[test]
fn test_read_code_discussion() {
    let discussions: Vec<Discussion> = read_test_file("discussion");
Ben Boeckel's avatar
Ben Boeckel committed
505
506
507
508
    let discussion = discussions
        .into_iter()
        .find(|x| x.id.value() == "9f4998b2308728b95cff52af97019479e1269183")
        .unwrap();
509
510
511
512
513
    assert!(!(discussion.individual_note));
    let note = discussion.notes.get(0).unwrap();
    assert!(note.resolvable);
    assert!(note.resolved.is_some());
    assert_eq!(note.author.username, "brad.king");
514
    assert_eq!(note.id, NoteId::new(619_272));
515
516
517
518
    assert_eq!(note.note_type, Some(DiscussionNoteType::DiffNote));
    assert!(note.position.is_some());
    if let Some(position) = &note.position {
        assert_eq!(position.position_type, NotePositionType::Text);
Ben Boeckel's avatar
Ben Boeckel committed
519
520
521
522
        assert_eq!(
            position.head_sha.value(),
            "04e94ae667024a62a90179f395bfdc2b35f3efd2",
        );
523
524
525
526
527
528
529
        assert_eq!(position.new_line, Some(156));
        assert_eq!(position.new_path, "src/gitlab.rs");
    } else {
        unreachable!();
    }
}

530
531
532
533
534
#[test]
fn test_read_project() {
    let project: Project = read_test_file("project");

    assert_eq!(project.id, ProjectId::new(855));
Ben Boeckel's avatar
Ben Boeckel committed
535
536
    assert_eq!(
        project.description,
537
        Some("Rust library for communicating with a Gitlab instance.".into()),
Ben Boeckel's avatar
Ben Boeckel committed
538
    );
539
    assert_eq!(project.default_branch, Some("master".into()));
540
541
    assert!(project.tag_list.is_empty());
    assert_eq!(project.archived, false);
Brad King's avatar
Brad King committed
542
    assert_eq!(project.empty_repo, false);
Brad King's avatar
Brad King committed
543
    assert_eq!(project.visibility, VisibilityLevel::Public);
Ben Boeckel's avatar
Ben Boeckel committed
544
545
546
547
548
549
550
551
552
553
554
555
556
557
    assert_eq!(
        project.ssh_url_to_repo,
        "git@gitlab.kitware.com:utils/rust-gitlab.git",
    );
    assert_eq!(
        project.http_url_to_repo,
        "https://gitlab.kitware.com/utils/rust-gitlab.git",
    );
    assert_eq!(
        project.web_url,
        "https://gitlab.kitware.com/utils/rust-gitlab",
    );
    assert_eq!(
        project.readme_url,
558
        Some("https://gitlab.kitware.com/utils/rust-gitlab/blob/master/README.md".into()),
Ben Boeckel's avatar
Ben Boeckel committed
559
    );
560
561
562
563
564
565
    assert!(project.owner.is_none());
    assert_eq!(project.name, "rust-gitlab");
    assert_eq!(project.name_with_namespace, "Utils / rust-gitlab");
    assert_eq!(project.path, "rust-gitlab");
    assert_eq!(project.path_with_namespace, "utils/rust-gitlab");
    assert_eq!(project.container_registry_enabled, Some(true));
Ben Boeckel's avatar
Ben Boeckel committed
566
567
568
569
570
571
    assert_eq!(
        project.created_at,
        Utc.ymd(2016, 6, 29).and_hms_milli(17, 35, 12, 495),
    );
    assert_eq!(
        project.last_activity_at,
Brad King's avatar
Brad King committed
572
        Utc.ymd(2019, 7, 30).and_hms_milli(16, 42, 57, 649),
Ben Boeckel's avatar
Ben Boeckel committed
573
    );
Brad King's avatar
Brad King committed
574
    assert_eq!(project.import_error, None);
575
576
577
578
579
    assert_eq!(project.shared_runners_enabled, true);
    assert_eq!(project.lfs_enabled, true);
    assert_eq!(project.creator_id, UserId::new(13));
    assert_eq!(project.namespace.name, "Utils");
    assert_eq!(project.namespace.path, "utils");
Ben Boeckel's avatar
Ben Boeckel committed
580
581
582
583
    assert_eq!(
        project.namespace.id(),
        NamespaceId::Group(GroupId::new(498)),
    );
Ben Boeckel's avatar
Ben Boeckel committed
584
    assert_eq!(project.namespace.kind, NamespaceKind::Group);
585
    assert_eq!(project.namespace.full_path, "utils");
Brad King's avatar
Brad King committed
586
    assert_eq!(project.namespace.avatar_url, None);
Ben Boeckel's avatar
Ben Boeckel committed
587
588
589
590
    assert_eq!(
        project.namespace.web_url,
        "https://gitlab.kitware.com/groups/utils",
    );
Brad King's avatar
Brad King committed
591
    assert!(project.namespace.members_count_with_descendants.is_none());
592
593
    assert!(project.forked_from_project.is_none());
    assert_eq!(project.avatar_url, None);
Brad King's avatar
Brad King committed
594
    assert_eq!(project.ci_config_path, None);
Brad King's avatar
Brad King committed
595
596
597
    assert_eq!(project.star_count, 6);
    assert_eq!(project.forks_count, 17);
    assert_eq!(project.open_issues_count, Some(8));
Brad King's avatar
Brad King committed
598
    assert_eq!(project.public_jobs, true);
599
    assert!(project.shared_with_groups.is_empty());
Brad King's avatar
Brad King committed
600
    assert_eq!(project.only_allow_merge_if_pipeline_succeeds, Some(false));
Ben Boeckel's avatar
Ben Boeckel committed
601
602
603
604
    assert_eq!(
        project.only_allow_merge_if_all_discussions_are_resolved,
        None,
    );
Brad King's avatar
Brad King committed
605
    assert_eq!(project.printing_merge_request_link_enabled, Some(true));
Brad King's avatar
Brad King committed
606
    assert_eq!(project.request_access_enabled, false);
Brad King's avatar
Brad King committed
607
    assert_eq!(project.resolve_outdated_diff_discussions, None);
608
609

    assert_eq!(project.jobs_enabled, false);
610
611
612
613
    assert_eq!(project.issues_enabled, true);
    assert_eq!(project.merge_requests_enabled, true);
    assert_eq!(project.snippets_enabled, false);
    assert_eq!(project.wiki_enabled, true);
614

Ben Boeckel's avatar
Ben Boeckel committed
615
616
617
618
    assert_eq!(
        project.builds_access_level,
        FeatureVisibilityLevel::Disabled,
    );
Brad King's avatar
Brad King committed
619
    assert_eq!(project.issues_access_level, FeatureVisibilityLevel::Enabled);
Ben Boeckel's avatar
Ben Boeckel committed
620
621
622
623
624
625
626
627
628
629
630
631
    assert_eq!(
        project.merge_requests_access_level,
        FeatureVisibilityLevel::Enabled,
    );
    assert_eq!(
        project.repository_access_level,
        FeatureVisibilityLevel::Enabled,
    );
    assert_eq!(
        project.snippets_access_level,
        FeatureVisibilityLevel::Disabled,
    );
Brad King's avatar
Brad King committed
632
633
    assert_eq!(project.wiki_access_level, FeatureVisibilityLevel::Enabled);

634
    assert_eq!(project.merge_method, Some("merge".into()));
635
636
637
638
639
640
641
642
    if let Some(ref permissions) = project.permissions {
        if let Some(ref group_access) = permissions.group_access {
            assert_eq!(group_access.access_level, 50);
            assert_eq!(group_access.notification_level, Some(3));
        } else {
            panic!("expected to have group access on the permissions");
        }
        assert!(permissions.project_access.is_none());
Ben Boeckel's avatar
Ben Boeckel committed
643
        assert!(project.has_links());
644
645
646
647
648
649
650
651
652
    } else {
        panic!("expected to have permissions available");
    }
}

#[test]
fn test_read_project_hook() {
    let project_hook: ProjectHook = read_test_file("project_hook");

653
654
    assert_eq!(project_hook.id, HookId::new(1262));
    assert_eq!(project_hook.url, "http://kwrobot02:8082/gitlab.kitware.com");
Ben Boeckel's avatar
Ben Boeckel committed
655
656
657
658
    assert_eq!(
        project_hook.created_at,
        Utc.ymd(2016, 12, 16).and_hms_milli(16, 37, 24, 589),
    );
659
    assert_eq!(project_hook.push_events, true);
Brad King's avatar
Brad King committed
660
    assert!(project_hook.push_events_branch_filter.is_none());
661
662
    assert_eq!(project_hook.tag_push_events, true);
    assert_eq!(project_hook.issues_events, true);
663
    assert_eq!(project_hook.confidential_issues_events, Some(true));
664
665
    assert_eq!(project_hook.merge_requests_events, true);
    assert_eq!(project_hook.note_events, true);
666
    assert_eq!(project_hook.confidential_note_events, Some(true));
Brad King's avatar
Brad King committed
667
    assert_eq!(project_hook.repository_update_events, false);
668
    assert_eq!(project_hook.enable_ssl_verification, true);
Brad King's avatar
Brad King committed
669
    assert_eq!(project_hook.job_events, true);
670
671
    assert_eq!(project_hook.pipeline_events, true);
    assert_eq!(project_hook.wiki_page_events, true);
672
673
674
675
676
677
678
679
}

#[test]
fn test_read_repo_branch() {
    let repo_branch: RepoBranch = read_test_file("repo_branch");

    assert_eq!(repo_branch.name, "master");
    if let Some(ref commit) = repo_branch.commit {
Brad King's avatar
Brad King committed
680
681
        assert_eq!(commit.author_email, "brad.king@kitware.com");
        assert_eq!(commit.author_name, "Brad King");
Ben Boeckel's avatar
Ben Boeckel committed
682
683
684
685
686
687
688
689
690
691
692
693
        assert_eq!(
            commit.authored_date,
            Utc.ymd(2018, 7, 12).and_hms_milli(12, 50, 24, 0),
        );
        assert_eq!(
            commit.committed_date,
            Utc.ymd(2018, 7, 12).and_hms_milli(12, 50, 24, 0),
        );
        assert_eq!(
            commit.created_at,
            Utc.ymd(2018, 7, 12).and_hms_milli(12, 50, 24, 0),
        );
Brad King's avatar
Brad King committed
694
695
        assert_eq!(commit.committer_email, "brad.king@kitware.com");
        assert_eq!(commit.committer_name, "Brad King");
Ben Boeckel's avatar
Ben Boeckel committed
696
697
698
699
        assert_eq!(
            commit.id,
            ObjectId::new("e59db4b129b29df220ecec6119ed2130207a0397"),
        );
Brad King's avatar
Brad King committed
700
701
702
        assert_eq!(commit.short_id, ObjectId::new("e59db4b1"));
        assert_eq!(commit.title, "cargo: prep for 0.1100.1");
        assert_eq!(commit.message, "cargo: prep for 0.1100.1\n");
Ben Boeckel's avatar
Ben Boeckel committed
703
704
705
706
        assert_eq!(
            commit.parent_ids,
            vec![ObjectId::new("5c81cc05661dcbb5fd923cca093920816c21ef7e")],
        );
707
708
709
    } else {
        panic!("expected to have a commit for the branch");
    }
710
    assert_eq!(repo_branch.merged, Some(false));
711
712
713
    assert_eq!(repo_branch.protected, Some(true));
    assert_eq!(repo_branch.developers_can_push, Some(false));
    assert_eq!(repo_branch.developers_can_merge, Some(false));
Brad King's avatar
Brad King committed
714
    assert_eq!(repo_branch.can_push, Some(true));
Brad King's avatar
Brad King committed
715
    assert_eq!(repo_branch.default, Some(true));
716
717
718
719
720
721
}

#[test]
fn test_read_repo_commit_detail() {
    let repo_commit_detail: RepoCommitDetail = read_test_file("repo_commit_detail");

Ben Boeckel's avatar
Ben Boeckel committed
722
723
724
725
    assert_eq!(
        repo_commit_detail.id,
        ObjectId::new("de4ac3cf96cb8a0893be22b03f5171d934f9d392"),
    );
726
727
728
729
    assert_eq!(repo_commit_detail.short_id, ObjectId::new("de4ac3cf"));
    assert_eq!(repo_commit_detail.title, "Merge topic 'mr-awards'");
    assert_eq!(repo_commit_detail.author_name, "Brad King");
    assert_eq!(repo_commit_detail.author_email, "brad.king@kitware.com");
730
731
    assert_eq!(repo_commit_detail.committer_name, "Kitware Robot");
    assert_eq!(repo_commit_detail.committer_email, "kwrobot@kitware.com");
Ben Boeckel's avatar
Ben Boeckel committed
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
    assert_eq!(
        repo_commit_detail.created_at,
        Utc.ymd(2016, 11, 8).and_hms_milli(14, 30, 13, 0),
    );
    assert_eq!(
        repo_commit_detail.message,
        "Merge topic 'mr-awards'\n\na222c553 gitlab: add a method for MR award \
         queries\n\nAcked-by: Kitware Robot <kwrobot@kitware.com>\nReviewed-by: Brad King \
         <brad.king@kitware.com>\nMerge-request: !46\n",
    );
    assert_eq!(
        repo_commit_detail.parent_ids,
        vec![
            ObjectId::new("559f5f4a2bfe1f48e9e95afa09c029deb655cf7d"),
            ObjectId::new("a222c5539569cda6999b8069f1e51a5202c30711")
        ],
    );
    assert_eq!(
        repo_commit_detail.committed_date,
        Utc.ymd(2016, 11, 8).and_hms_milli(14, 30, 13, 0),
    );
    assert_eq!(
        repo_commit_detail.authored_date,
        Utc.ymd(2016, 11, 8).and_hms_milli(14, 30, 13, 0),
    );
Brad King's avatar
Brad King committed
757
758
759
760
761
762
763
    if let Some(ref stats) = repo_commit_detail.stats {
        assert_eq!(stats.additions, 8);
        assert_eq!(stats.deletions, 0);
        assert_eq!(stats.total, 8);
    } else {
        panic!("expected to have stats for this commit");
    }
Brad King's avatar
Brad King committed
764
765
    if let Some(ref last_pipeline) = repo_commit_detail.last_pipeline {
        assert_eq!(last_pipeline.id, PipelineId::new(34289));
766
        assert_eq!(last_pipeline.ref_, Some("master".into()));
Ben Boeckel's avatar
Ben Boeckel committed
767
768
769
770
        assert_eq!(
            last_pipeline.sha,
            ObjectId::new("de4ac3cf96cb8a0893be22b03f5171d934f9d392"),
        );
Brad King's avatar
Brad King committed
771
        assert_eq!(last_pipeline.status, StatusState::Success);
Ben Boeckel's avatar
Ben Boeckel committed
772
773
        assert_eq!(
            last_pipeline.web_url,
774
            "https://gitlab.kitware.com/utils/rust-gitlab/pipelines/34289",
Ben Boeckel's avatar
Ben Boeckel committed
775
        );
Brad King's avatar
Brad King committed
776
777
778
    } else {
        panic!("expected to have a last_pipeline for this commit");
    }
Brad King's avatar
Brad King committed
779
    assert_eq!(repo_commit_detail.project_id, ProjectId::new(855));
780
}
Ben Boeckel's avatar
Ben Boeckel committed
781
782
783
784
785

#[test]
fn test_read_user() {
    let user: User = read_test_file("user");

786
787
788
    assert_eq!(user.username, "kwrobot");
    assert_eq!(user.name, "Kitware Robot");
    assert_eq!(user.id, UserId::new(11));
Ben Boeckel's avatar
Ben Boeckel committed
789
    assert_eq!(user.state, UserState::Active);
Ben Boeckel's avatar
Ben Boeckel committed
790
791
792
793
    assert_eq!(
        user.avatar_url,
        Some(
            "https://secure.gravatar.com/avatar/9ddcd45fcb89d966aab95b1f1002f84c?s=80&d=identicon"
794
                .into()
Ben Boeckel's avatar
Ben Boeckel committed
795
796
        ),
    );
797
    assert_eq!(user.web_url, "https://gitlab.kitware.com/kwrobot");
Ben Boeckel's avatar
Ben Boeckel committed
798
799
800
801
    assert_eq!(
        user.created_at,
        Some(Utc.ymd(2015, 2, 26).and_hms_milli(15, 58, 34, 670)),
    );
802
    assert_eq!(user.is_admin, None);
Brad King's avatar
Brad King committed
803
    assert_eq!(user.highest_role, Some(AccessLevel::Owner));
804
    assert_eq!(user.bio, Some("".into()));
Brad King's avatar
Brad King committed
805
    assert_eq!(user.private_profile, Some(false));
Ben Boeckel's avatar
Ben Boeckel committed
806
    assert_eq!(user.location, None);
807
    assert_eq!(user.public_email, Some("".into()));
Ben Boeckel's avatar
Ben Boeckel committed
808
809
810
811
    assert_eq!(user.skype, "");
    assert_eq!(user.linkedin, "");
    assert_eq!(user.twitter, "");
    assert_eq!(user.website_url, "");
812
813
814
815
    assert_eq!(user.organization, None);
}

#[test]
816
817
818
fn test_read_user_public() {
    let user_public: UserPublic = read_test_file("user_public");

Brad King's avatar
Brad King committed
819
820
821
    assert_eq!(user_public.username, "kwrobot");
    assert_eq!(user_public.name, "Kitware Robot");
    assert_eq!(user_public.id, UserId::new(11));
822
    assert_eq!(user_public.state, UserState::Active);
Ben Boeckel's avatar
Ben Boeckel committed
823
824
825
826
    assert_eq!(
        user_public.avatar_url,
        Some(
            "https://secure.gravatar.com/avatar/9ddcd45fcb89d966aab95b1f1002f84c?s=80&d=identicon"
827
                .into()
Ben Boeckel's avatar
Ben Boeckel committed
828
829
830
831
832
833
834
        ),
    );
    assert_eq!(user_public.web_url, "https://gitlab.kitware.com/kwrobot");
    assert_eq!(
        user_public.created_at,
        Some(Utc.ymd(2015, 2, 26).and_hms_milli(15, 58, 34, 670)),
    );
Brad King's avatar
Brad King committed
835
    assert_eq!(user_public.is_admin, Some(true));
836
    assert_eq!(user_public.bio, Some("".into()));
Brad King's avatar
Brad King committed
837
    assert_eq!(user_public.private_profile, Some(false));
838
    assert_eq!(user_public.location, None);
839
    assert_eq!(user_public.public_email, Some("".into()));
840
841
842
843
844
    assert_eq!(user_public.skype, "");
    assert_eq!(user_public.linkedin, "");
    assert_eq!(user_public.twitter, "");
    assert_eq!(user_public.website_url, "");
    assert_eq!(user_public.organization, None);
Ben Boeckel's avatar
Ben Boeckel committed
845
846
847
848
849
850
851
852
853
854
855
856
    assert_eq!(
        user_public.last_sign_in_at,
        Some(Utc.ymd(2018, 10, 8).and_hms_milli(17, 25, 29, 86)),
    );
    assert_eq!(
        user_public.last_activity_on,
        Some(NaiveDate::from_ymd(2018, 10, 25)),
    );
    assert_eq!(
        user_public.confirmed_at,
        Some(Utc.ymd(2015, 2, 26).and_hms_milli(15, 58, 34, 660)),
    );
Brad King's avatar
Brad King committed
857
    assert_eq!(user_public.email, "kwrobot@kitware.com");
Brad King's avatar
Brad King committed
858
    assert_eq!(user_public.theme_id, None);
Brad King's avatar
Brad King committed
859
    assert_eq!(user_public.color_scheme_id, ColorSchemeId::new(4));
860
    assert_eq!(user_public.projects_limit, 50);
Ben Boeckel's avatar
Ben Boeckel committed
861
862
863
864
    assert_eq!(
        user_public.current_sign_in_at,
        Some(Utc.ymd(2018, 10, 11).and_hms_milli(12, 36, 9, 687)),
    );
865
866
867
868
869
    assert!(user_public.identities.is_empty());
    assert_eq!(user_public.can_create_group, true);
    assert_eq!(user_public.can_create_project, true);
    assert_eq!(user_public.two_factor_enabled, true);
    assert_eq!(user_public.external, false);
Ben Boeckel's avatar
Ben Boeckel committed
870
}
Andrew Chin's avatar
Andrew Chin committed
871
872
873
874
875
876
877
878

#[test]
fn test_read_resoruce_label_events() {
    let event: ResourceLabelEvent = read_test_file("resource_label_event");

    assert_eq!(event.id, LabelEventId::new(10945));
    assert_eq!(event.user.id, UserId::new(10));
    assert_eq!(event.user.username, "brad.king");
879
880
881
882
883

    match &event.event_target() {
        Some(ResourceLabelEventTarget::Issue(id)) if id.value() == 69328 => {
            // this is the expected value
        },
Ben Boeckel's avatar
Ben Boeckel committed
884
        x => panic!("Unexpected resource_target: {:?}", x),
885
886
    }

Andrew Chin's avatar
Andrew Chin committed
887
888
889
890
    let label = event.label.unwrap();
    assert_eq!(label.id, LabelId::new(1720));
    assert_eq!(label.name, "area:doc");
    assert_eq!(label.color, LabelColor::from_rgb(0x58, 0x43, 0xAD));
891
    assert_eq!(label.description, Some("Documentation issues".into()));
Andrew Chin's avatar
Andrew Chin committed
892
}
893
894
895
896
897

#[test]
fn test_read_pipelines() {
    let pipeline_basic: PipelineBasic = read_test_file("pipeline_basic");

898
    assert_eq!(pipeline_basic.id, PipelineId::new(145_400));
Ben Boeckel's avatar
Ben Boeckel committed
899
    assert_eq!(pipeline_basic.status, StatusState::Success);
900
    assert_eq!(pipeline_basic.ref_, Some("master".into()));
Ben Boeckel's avatar
Ben Boeckel committed
901
902
    assert_eq!(
        pipeline_basic.sha,
903
        ObjectId::new("7134adce4522c399cdab16e128b0a1af15b93f14"),
Ben Boeckel's avatar
Ben Boeckel committed
904
905
906
907
908
    );
    assert_eq!(
        pipeline_basic.web_url,
        "https://gitlab.kitware.com/utils/rust-gitlab/pipelines/145400",
    );
909
910
911
912
913
914
}

#[test]
fn test_read_pipeline() {
    let pipeline: Pipeline = read_test_file("pipeline");

915
    assert_eq!(pipeline.id, PipelineId::new(145_400));
916
    assert_eq!(pipeline.status, StatusState::Success);
917
    assert_eq!(pipeline.ref_, Some("master".into()));
Ben Boeckel's avatar
Ben Boeckel committed
918
919
    assert_eq!(
        pipeline.sha,
920
        ObjectId::new("7134adce4522c399cdab16e128b0a1af15b93f14"),
Ben Boeckel's avatar
Ben Boeckel committed
921
    );
922
923
924
    assert_eq!(pipeline.before_sha, None);
    assert_eq!(pipeline.tag, false);
    assert_eq!(pipeline.yaml_errors, None);
Ben Boeckel's avatar
Ben Boeckel committed
925
926
    assert_eq!(
        pipeline.created_at,
927
        Some(Utc.ymd(2019, 9, 3).and_hms_milli(18, 9, 47, 178)),
Ben Boeckel's avatar
Ben Boeckel committed
928
929
930
931
932
933
934
    );
    assert_eq!(
        pipeline.updated_at,
        Some(Utc.ymd(2019, 9, 3).and_hms_milli(18, 15, 47, 18)),
    );
    assert_eq!(
        pipeline.started_at,
935
        Some(Utc.ymd(2019, 9, 3).and_hms_milli(18, 9, 51, 465)),
Ben Boeckel's avatar
Ben Boeckel committed
936
937
938
939
940
    );
    assert_eq!(
        pipeline.finished_at,
        Some(Utc.ymd(2019, 9, 3).and_hms_milli(18, 15, 47, 13)),
    );
941
942
943
    assert_eq!(pipeline.committed_at, None);
    assert_eq!(pipeline.duration, Some(0));
    assert_eq!(pipeline.coverage, None);
Ben Boeckel's avatar
Ben Boeckel committed
944
945
946
947
    assert_eq!(
        pipeline.web_url,
        "https://gitlab.kitware.com/utils/rust-gitlab/pipelines/145400",
    );
948
949

    // nested user
Ben Boeckel's avatar
Ben Boeckel committed
950
951
952
953
954
955
956
    assert_eq!(
        pipeline.user.avatar_url,
        Some(
            "https://gitlab.kitware.com/uploads/-/system/user/avatar/35/buildbot-logo.png"
                .to_owned(),
        ),
    );
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
    assert_eq!(pipeline.user.id, UserId::new(35));
    assert_eq!(pipeline.user.name, "buildbot");
    assert_eq!(pipeline.user.username, "buildbot");
    assert_eq!(pipeline.user.state, UserState::Active);
    assert_eq!(pipeline.user.web_url, "https://gitlab.kitware.com/buildbot");

    // nested detailed status
    assert_eq!(
        pipeline.detailed_status,
        json!({
            "details_path": "/utils/rust-gitlab/pipelines/145400",
            "favicon": "/assets/ci_favicons/favicon_status_success-8451333011eee8ce9f2ab25dc487fe24a8758c694827a582f17f42b0a90446a2.png",
            "group": "success",
            "has_details": true,
            "icon": "status_success",
            "illustration": null,
            "label": "passed",
            "text": "passed",
            "tooltip": "passed"
        }),
    );
}

#[test]
fn test_read_pipeline_variables() {
    let var: PipelineVariable = read_test_file("pipeline_variable");

    assert_eq!(var.key, "RUN_NIGHTLY_BUILD");
    assert_eq!(var.variable_type, PipelineVariableType::EnvVar);
    assert_eq!(var.value, "true");
}