chrome-for-testing 0.4.0

Interact with the chrome-for-testing JSON API.
Documentation
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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
use crate::api::channel::Channel;
use crate::api::platform::Platform;
use crate::api::version::Version;
use crate::api::{API_BASE_URL, Download, DownloadsByPlatform, fetch_endpoint};
use serde::de::Error as DeError;
use serde::{Deserialize, Serialize};
use std::borrow::Borrow;
use std::collections::HashMap;

/// JSON Example:
/// ```json
/// {
///     "timestamp": "2025-01-05T22:09:08.729Z",
///     "channels": {
///         "Stable": {
///             "channel": "Stable",
///             "version": "131.0.6778.204",
///             "revision": "1368529",
///             "downloads": {
///                 "chrome": [
///                     {
///                         "platform": "linux64",
///                         "url": "https://storage.googleapis.com/chrome-for-testing-public/131.0.6778.204/linux64/chrome-linux64.zip"
///                     },
///                     {
///                         "platform": "mac-arm64",
///                         "url": "https://storage.googleapis.com/chrome-for-testing-public/131.0.6778.204/mac-arm64/chrome-mac-arm64.zip"
///                     },
///                     {
///                         "platform": "mac-x64",
///                         "url": "https://storage.googleapis.com/chrome-for-testing-public/131.0.6778.204/mac-x64/chrome-mac-x64.zip"
///                     },
///                     {
///                         "platform": "win32",
///                         "url": "https://storage.googleapis.com/chrome-for-testing-public/131.0.6778.204/win32/chrome-win32.zip"
///                     },
///                     {
///                         "platform": "win64",
///                         "url": "https://storage.googleapis.com/chrome-for-testing-public/131.0.6778.204/win64/chrome-win64.zip"
///                     }
///                 ],
///                 "chromedriver": [
///                     {
///                         "platform": "linux64",
///                         "url": "https://storage.googleapis.com/chrome-for-testing-public/131.0.6778.204/linux64/chromedriver-linux64.zip"
///                     },
///                     ...
///                 ],
///                 "chrome-headless-shell": [
///                     {
///                         "platform": "linux64",
///                         "url": "https://storage.googleapis.com/chrome-for-testing-public/131.0.6778.204/linux64/chrome-headless-shell-linux64.zip"
///                     },
///                     ...
///                 ]
///             }
///         },
///         "Beta": {
///             "channel": "Beta",
///             "version": "132.0.6834.57",
///             "revision": "1381561",
///             "downloads": {
///                 "chrome": [
///                    ...
///                 ],
///                 "chromedriver": [
///                     ...
///                 ],
///                 "chrome-headless-shell": [
///                     ...
///                 ]
///             }
///         },
///         "Dev": { ... },
///         "Canary": { ... }
///     }
/// }
/// ```
const LAST_KNOWN_GOOD_VERSIONS_WITH_DOWNLOADS_JSON_PATH: &str =
    "/chrome-for-testing/last-known-good-versions-with-downloads.json";

/// Download links for Chrome, `ChromeDriver`, and Chrome Headless Shell binaries for various
/// platforms.
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct Downloads {
    /// Download links for Chrome binaries for various platforms.
    pub chrome: Vec<Download>,

    /// Download links for `ChromeDriver` binaries for various platforms.
    pub chromedriver: Vec<Download>,

    /// The "chrome-headless-shell" binary provides the "old" headless mode of Chrome, as described
    /// in [this blog post](https://developer.chrome.com/blog/chrome-headless-shell).
    /// For standard automated web-ui testing, you should pretty much always use the regular
    /// `chrome` binary instead.
    #[serde(rename = "chrome-headless-shell")]
    pub chrome_headless_shell: Vec<Download>,
}

impl Downloads {
    /// Returns the Chrome download entry for the given platform, if available.
    #[must_use]
    pub fn chrome_for_platform(&self, platform: Platform) -> Option<&Download> {
        self.chrome.for_platform(platform)
    }

    /// Returns the `ChromeDriver` download entry for the given platform, if available.
    #[must_use]
    pub fn chromedriver_for_platform(&self, platform: Platform) -> Option<&Download> {
        self.chromedriver.for_platform(platform)
    }

    /// Returns the Chrome Headless Shell download entry for the given platform, if available.
    #[must_use]
    pub fn chrome_headless_shell_for_platform(&self, platform: Platform) -> Option<&Download> {
        self.chrome_headless_shell.for_platform(platform)
    }
}

/// A Chrome version entry with channel information.
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct VersionInChannel {
    /// The release channel this version belongs to.
    pub channel: Channel,

    /// The version identifier.
    pub version: Version,

    /// The Chromium revision number.
    pub revision: String,

    /// Available downloads for this version.
    pub downloads: Downloads,
}

fn deserialize_channels<'de, D>(
    deserializer: D,
) -> Result<HashMap<Channel, VersionInChannel>, D::Error>
where
    D: serde::Deserializer<'de>,
{
    let channels = HashMap::<Channel, VersionInChannel>::deserialize(deserializer)?;

    for (key, value) in &channels {
        if key != &value.channel {
            return Err(D::Error::custom(format!(
                "expected channels.{key}.channel to be {key}, got {}",
                value.channel
            )));
        }
    }

    Ok(channels)
}

/// Response structure for the "last known good versions" API endpoint.
///
/// Contains the most recent version for each Chrome release channel (Stable, Beta, Dev, Canary).
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct LastKnownGoodVersions {
    /// When this data was last updated.
    #[serde(with = "time::serde::rfc3339")]
    pub timestamp: time::OffsetDateTime,

    /// The latest known good version for each release channel.
    ///
    /// The Chrome for Testing docs currently define Stable, Beta, Dev, and Canary for this
    /// endpoint, but this remains a map so the crate can preserve newly-added upstream channels
    /// instead of discarding them.
    #[serde(deserialize_with = "deserialize_channels")]
    channels: HashMap<Channel, VersionInChannel>,
}

impl LastKnownGoodVersions {
    /// Fetches the last known good versions from the Chrome for Testing API.
    ///
    /// Returns the most recent version for each Chrome release channel (Stable, Beta, Dev, Canary).
    ///
    /// # Errors
    ///
    /// Returns an error if the HTTP request fails, the response has an unsuccessful status, or
    /// deserialization fails.
    pub async fn fetch(client: &reqwest::Client) -> crate::Result<Self> {
        Self::fetch_with_base_url(client, &API_BASE_URL).await
    }

    /// Fetches from a custom base URL (useful for testing).
    ///
    /// # Errors
    ///
    /// Returns an error if the HTTP request fails, the response has an unsuccessful status, or
    /// deserialization fails.
    pub async fn fetch_with_base_url(
        client: &reqwest::Client,
        base_url: &reqwest::Url,
    ) -> crate::Result<LastKnownGoodVersions> {
        fetch_endpoint::<Self>(
            client,
            base_url,
            LAST_KNOWN_GOOD_VERSIONS_WITH_DOWNLOADS_JSON_PATH,
            "LastKnownGoodVersions",
        )
        .await
    }

    /// Returns the version info for the given channel.
    #[must_use]
    pub fn channel(&self, channel: impl Borrow<Channel>) -> Option<&VersionInChannel> {
        self.channels.get(channel.borrow())
    }

    /// Returns the latest known good versions by release channel.
    #[must_use]
    pub fn channels(&self) -> &HashMap<Channel, VersionInChannel> {
        &self.channels
    }

    /// Returns the Stable channel version info, if present.
    #[must_use]
    pub fn stable(&self) -> Option<&VersionInChannel> {
        self.channel(Channel::Stable)
    }

    /// Returns the Beta channel version info, if present.
    #[must_use]
    pub fn beta(&self) -> Option<&VersionInChannel> {
        self.channel(Channel::Beta)
    }

    /// Returns the Dev channel version info, if present.
    #[must_use]
    pub fn dev(&self) -> Option<&VersionInChannel> {
        self.channel(Channel::Dev)
    }

    /// Returns the Canary channel version info, if present.
    #[must_use]
    pub fn canary(&self) -> Option<&VersionInChannel> {
        self.channel(Channel::Canary)
    }
}

#[cfg(test)]
mod tests {
    use crate::api::Download;
    use crate::api::channel::Channel;
    use crate::api::last_known_good_versions::{
        Downloads, LAST_KNOWN_GOOD_VERSIONS_WITH_DOWNLOADS_JSON_PATH, LastKnownGoodVersions,
        VersionInChannel,
    };
    use crate::api::platform::Platform;
    use crate::api::version::Version;
    use crate::error::Error;
    use assertr::prelude::*;
    use std::collections::HashMap;
    use time::macros::datetime;
    use url::Url;

    // This test should not be `#[ignore]`, even though it hits the Chrome For Testing API.
    #[tokio::test]
    async fn can_request_from_real_world_endpoint() {
        let result = LastKnownGoodVersions::fetch(&reqwest::Client::new()).await;
        assert_that!(result).is_ok();
    }

    //noinspection DuplicatedCode
    #[tokio::test]
    #[allow(clippy::too_many_lines)]
    async fn can_query_last_known_good_versions_api_endpoint_and_deserialize_response() {
        let mut server = mockito::Server::new_async().await;
        let _mock = server
            .mock("GET", LAST_KNOWN_GOOD_VERSIONS_WITH_DOWNLOADS_JSON_PATH)
            .with_status(200)
            .with_header("content-type", "application/json")
            .with_body(include_str!(
                "./../../test-data/last_known_good_versions_with_downloads_test_response.json"
            ))
            .create();

        let url: Url = server.url().parse().unwrap();

        let data = LastKnownGoodVersions::fetch_with_base_url(&reqwest::Client::new(), &url)
            .await
            .unwrap();

        assert_that!(data).is_equal_to(LastKnownGoodVersions {
            timestamp: datetime!(2026-04-13 08:53:52.841 UTC),
            channels: HashMap::from([
                (
                    Channel::Stable,
                    VersionInChannel {
                    channel: Channel::Stable,
                    version: Version { major: 147, minor: 0, patch: 7727, build: 56 },
                    revision: String::from("1596535"),
                    downloads: Downloads {
                        chrome: vec![
                            Download { platform: Platform::Linux64, url: String::from("https://storage.googleapis.com/chrome-for-testing-public/147.0.7727.56/linux64/chrome-linux64.zip") },
                            Download { platform: Platform::MacArm64, url: String::from("https://storage.googleapis.com/chrome-for-testing-public/147.0.7727.56/mac-arm64/chrome-mac-arm64.zip") },
                            Download { platform: Platform::MacX64, url: String::from("https://storage.googleapis.com/chrome-for-testing-public/147.0.7727.56/mac-x64/chrome-mac-x64.zip") },
                            Download { platform: Platform::Win32, url: String::from("https://storage.googleapis.com/chrome-for-testing-public/147.0.7727.56/win32/chrome-win32.zip") },
                            Download { platform: Platform::Win64, url: String::from("https://storage.googleapis.com/chrome-for-testing-public/147.0.7727.56/win64/chrome-win64.zip") },
                        ],
                        chromedriver: vec![
                            Download { platform: Platform::Linux64, url: String::from("https://storage.googleapis.com/chrome-for-testing-public/147.0.7727.56/linux64/chromedriver-linux64.zip") },
                            Download { platform: Platform::MacArm64, url: String::from("https://storage.googleapis.com/chrome-for-testing-public/147.0.7727.56/mac-arm64/chromedriver-mac-arm64.zip") },
                            Download { platform: Platform::MacX64, url: String::from("https://storage.googleapis.com/chrome-for-testing-public/147.0.7727.56/mac-x64/chromedriver-mac-x64.zip") },
                            Download { platform: Platform::Win32, url: String::from("https://storage.googleapis.com/chrome-for-testing-public/147.0.7727.56/win32/chromedriver-win32.zip") },
                            Download { platform: Platform::Win64, url: String::from("https://storage.googleapis.com/chrome-for-testing-public/147.0.7727.56/win64/chromedriver-win64.zip") },
                        ],
                        chrome_headless_shell: vec![
                            Download { platform: Platform::Linux64, url: String::from("https://storage.googleapis.com/chrome-for-testing-public/147.0.7727.56/linux64/chrome-headless-shell-linux64.zip") },
                            Download { platform: Platform::MacArm64, url: String::from("https://storage.googleapis.com/chrome-for-testing-public/147.0.7727.56/mac-arm64/chrome-headless-shell-mac-arm64.zip") },
                            Download { platform: Platform::MacX64, url: String::from("https://storage.googleapis.com/chrome-for-testing-public/147.0.7727.56/mac-x64/chrome-headless-shell-mac-x64.zip") },
                            Download { platform: Platform::Win32, url: String::from("https://storage.googleapis.com/chrome-for-testing-public/147.0.7727.56/win32/chrome-headless-shell-win32.zip") },
                            Download { platform: Platform::Win64, url: String::from("https://storage.googleapis.com/chrome-for-testing-public/147.0.7727.56/win64/chrome-headless-shell-win64.zip") },
                        ],
                    },
                    }
                ),
                (Channel::Beta, VersionInChannel {
                    channel: Channel::Beta,
                    version: Version { major: 148, minor: 0, patch: 7778, build: 5 },
                    revision: String::from("1610480"),
                    downloads: Downloads {
                        chrome: vec![
                            Download { platform: Platform::Linux64, url: String::from("https://storage.googleapis.com/chrome-for-testing-public/148.0.7778.5/linux64/chrome-linux64.zip") },
                            Download { platform: Platform::MacArm64, url: String::from("https://storage.googleapis.com/chrome-for-testing-public/148.0.7778.5/mac-arm64/chrome-mac-arm64.zip") },
                            Download { platform: Platform::MacX64, url: String::from("https://storage.googleapis.com/chrome-for-testing-public/148.0.7778.5/mac-x64/chrome-mac-x64.zip") },
                            Download { platform: Platform::Win32, url: String::from("https://storage.googleapis.com/chrome-for-testing-public/148.0.7778.5/win32/chrome-win32.zip") },
                            Download { platform: Platform::Win64, url: String::from("https://storage.googleapis.com/chrome-for-testing-public/148.0.7778.5/win64/chrome-win64.zip") },
                        ],
                        chromedriver: vec![
                            Download { platform: Platform::Linux64, url: String::from("https://storage.googleapis.com/chrome-for-testing-public/148.0.7778.5/linux64/chromedriver-linux64.zip") },
                            Download { platform: Platform::MacArm64, url: String::from("https://storage.googleapis.com/chrome-for-testing-public/148.0.7778.5/mac-arm64/chromedriver-mac-arm64.zip") },
                            Download { platform: Platform::MacX64, url: String::from("https://storage.googleapis.com/chrome-for-testing-public/148.0.7778.5/mac-x64/chromedriver-mac-x64.zip") },
                            Download { platform: Platform::Win32, url: String::from("https://storage.googleapis.com/chrome-for-testing-public/148.0.7778.5/win32/chromedriver-win32.zip") },
                            Download { platform: Platform::Win64, url: String::from("https://storage.googleapis.com/chrome-for-testing-public/148.0.7778.5/win64/chromedriver-win64.zip") },
                        ],
                        chrome_headless_shell: vec![
                            Download { platform: Platform::Linux64, url: String::from("https://storage.googleapis.com/chrome-for-testing-public/148.0.7778.5/linux64/chrome-headless-shell-linux64.zip") },
                            Download { platform: Platform::MacArm64, url: String::from("https://storage.googleapis.com/chrome-for-testing-public/148.0.7778.5/mac-arm64/chrome-headless-shell-mac-arm64.zip") },
                            Download { platform: Platform::MacX64, url: String::from("https://storage.googleapis.com/chrome-for-testing-public/148.0.7778.5/mac-x64/chrome-headless-shell-mac-x64.zip") },
                            Download { platform: Platform::Win32, url: String::from("https://storage.googleapis.com/chrome-for-testing-public/148.0.7778.5/win32/chrome-headless-shell-win32.zip") },
                            Download { platform: Platform::Win64, url: String::from("https://storage.googleapis.com/chrome-for-testing-public/148.0.7778.5/win64/chrome-headless-shell-win64.zip") },
                        ],
                    },
                }),
                (Channel::Dev, VersionInChannel {
                    channel: Channel::Dev,
                    version: Version { major: 148, minor: 0, patch: 7766, build: 3 },
                    revision: String::from("1607787"),
                    downloads: Downloads {
                        chrome: vec![
                            Download { platform: Platform::Linux64, url: String::from("https://storage.googleapis.com/chrome-for-testing-public/148.0.7766.3/linux64/chrome-linux64.zip") },
                            Download { platform: Platform::MacArm64, url: String::from("https://storage.googleapis.com/chrome-for-testing-public/148.0.7766.3/mac-arm64/chrome-mac-arm64.zip") },
                            Download { platform: Platform::MacX64, url: String::from("https://storage.googleapis.com/chrome-for-testing-public/148.0.7766.3/mac-x64/chrome-mac-x64.zip") },
                            Download { platform: Platform::Win32, url: String::from("https://storage.googleapis.com/chrome-for-testing-public/148.0.7766.3/win32/chrome-win32.zip") },
                            Download { platform: Platform::Win64, url: String::from("https://storage.googleapis.com/chrome-for-testing-public/148.0.7766.3/win64/chrome-win64.zip") },
                        ],
                        chromedriver: vec![
                            Download { platform: Platform::Linux64, url: String::from("https://storage.googleapis.com/chrome-for-testing-public/148.0.7766.3/linux64/chromedriver-linux64.zip") },
                            Download { platform: Platform::MacArm64, url: String::from("https://storage.googleapis.com/chrome-for-testing-public/148.0.7766.3/mac-arm64/chromedriver-mac-arm64.zip") },
                            Download { platform: Platform::MacX64, url: String::from("https://storage.googleapis.com/chrome-for-testing-public/148.0.7766.3/mac-x64/chromedriver-mac-x64.zip") },
                            Download { platform: Platform::Win32, url: String::from("https://storage.googleapis.com/chrome-for-testing-public/148.0.7766.3/win32/chromedriver-win32.zip") },
                            Download { platform: Platform::Win64, url: String::from("https://storage.googleapis.com/chrome-for-testing-public/148.0.7766.3/win64/chromedriver-win64.zip") },
                        ],
                        chrome_headless_shell: vec![
                            Download { platform: Platform::Linux64, url: String::from("https://storage.googleapis.com/chrome-for-testing-public/148.0.7766.3/linux64/chrome-headless-shell-linux64.zip") },
                            Download { platform: Platform::MacArm64, url: String::from("https://storage.googleapis.com/chrome-for-testing-public/148.0.7766.3/mac-arm64/chrome-headless-shell-mac-arm64.zip") },
                            Download { platform: Platform::MacX64, url: String::from("https://storage.googleapis.com/chrome-for-testing-public/148.0.7766.3/mac-x64/chrome-headless-shell-mac-x64.zip") },
                            Download { platform: Platform::Win32, url: String::from("https://storage.googleapis.com/chrome-for-testing-public/148.0.7766.3/win32/chrome-headless-shell-win32.zip") },
                            Download { platform: Platform::Win64, url: String::from("https://storage.googleapis.com/chrome-for-testing-public/148.0.7766.3/win64/chrome-headless-shell-win64.zip") },
                        ],
                    },
                }),
                (Channel::Canary, VersionInChannel {
                    channel: Channel::Canary,
                    version: Version { major: 149, minor: 0, patch: 7789, build: 0 },
                    revision: String::from("1613465"),
                    downloads: Downloads {
                        chrome: vec![
                            Download { platform: Platform::Linux64, url: String::from("https://storage.googleapis.com/chrome-for-testing-public/149.0.7789.0/linux64/chrome-linux64.zip") },
                            Download { platform: Platform::MacArm64, url: String::from("https://storage.googleapis.com/chrome-for-testing-public/149.0.7789.0/mac-arm64/chrome-mac-arm64.zip") },
                            Download { platform: Platform::MacX64, url: String::from("https://storage.googleapis.com/chrome-for-testing-public/149.0.7789.0/mac-x64/chrome-mac-x64.zip") },
                            Download { platform: Platform::Win32, url: String::from("https://storage.googleapis.com/chrome-for-testing-public/149.0.7789.0/win32/chrome-win32.zip") },
                            Download { platform: Platform::Win64, url: String::from("https://storage.googleapis.com/chrome-for-testing-public/149.0.7789.0/win64/chrome-win64.zip") },
                        ],
                        chromedriver: vec![
                            Download { platform: Platform::Linux64, url: String::from("https://storage.googleapis.com/chrome-for-testing-public/149.0.7789.0/linux64/chromedriver-linux64.zip") },
                            Download { platform: Platform::MacArm64, url: String::from("https://storage.googleapis.com/chrome-for-testing-public/149.0.7789.0/mac-arm64/chromedriver-mac-arm64.zip") },
                            Download { platform: Platform::MacX64, url: String::from("https://storage.googleapis.com/chrome-for-testing-public/149.0.7789.0/mac-x64/chromedriver-mac-x64.zip") },
                            Download { platform: Platform::Win32, url: String::from("https://storage.googleapis.com/chrome-for-testing-public/149.0.7789.0/win32/chromedriver-win32.zip") },
                            Download { platform: Platform::Win64, url: String::from("https://storage.googleapis.com/chrome-for-testing-public/149.0.7789.0/win64/chromedriver-win64.zip") },
                        ],
                        chrome_headless_shell: vec![
                            Download { platform: Platform::Linux64, url: String::from("https://storage.googleapis.com/chrome-for-testing-public/149.0.7789.0/linux64/chrome-headless-shell-linux64.zip") },
                            Download { platform: Platform::MacArm64, url: String::from("https://storage.googleapis.com/chrome-for-testing-public/149.0.7789.0/mac-arm64/chrome-headless-shell-mac-arm64.zip") },
                            Download { platform: Platform::MacX64, url: String::from("https://storage.googleapis.com/chrome-for-testing-public/149.0.7789.0/mac-x64/chrome-headless-shell-mac-x64.zip") },
                            Download { platform: Platform::Win32, url: String::from("https://storage.googleapis.com/chrome-for-testing-public/149.0.7789.0/win32/chrome-headless-shell-win32.zip") },
                            Download { platform: Platform::Win64, url: String::from("https://storage.googleapis.com/chrome-for-testing-public/149.0.7789.0/win64/chrome-headless-shell-win64.zip") },
                        ],
                    },
                }),
            ]),
        });
    }

    #[tokio::test]
    async fn unsuccessful_http_status_is_reported_as_request_error() {
        let mut server = mockito::Server::new_async().await;
        let _mock = server
            .mock("GET", LAST_KNOWN_GOOD_VERSIONS_WITH_DOWNLOADS_JSON_PATH)
            .with_status(500)
            .with_header("content-type", "application/json")
            .with_body(include_str!(
                "./../../test-data/last_known_good_versions_with_downloads_test_response.json"
            ))
            .create();

        let url: Url = server.url().parse().unwrap();

        let err = LastKnownGoodVersions::fetch_with_base_url(&reqwest::Client::new(), &url)
            .await
            .unwrap_err();

        let Error::Request(request_error) = err.current_context() else {
            panic!("expected request error, got: {:?}", err.current_context());
        };

        assert_that!(request_error.status())
            .is_equal_to(Some(reqwest::StatusCode::INTERNAL_SERVER_ERROR));
    }

    #[test]
    fn deserialization_rejects_channel_mismatch() {
        let json = include_str!(
            "./../../test-data/last_known_good_versions_with_downloads_test_response.json"
        )
        .replacen(r#""channel": "Stable""#, r#""channel": "Beta""#, 1);

        let result = serde_json::from_str::<LastKnownGoodVersions>(&json);

        assert_that!(result)
            .is_err()
            .derive(|it| it.to_string())
            .contains("expected channels.Stable.channel to be Stable, got Beta");
    }

    #[test]
    fn deserialization_preserves_unknown_channels() {
        let json = include_str!(
            "./../../test-data/last_known_good_versions_with_downloads_test_response.json"
        )
        .replacen(r#""Canary": {"#, r#""Extended": {"#, 1)
        .replacen(r#""channel": "Canary""#, r#""channel": "Extended""#, 1);

        let data = serde_json::from_str::<LastKnownGoodVersions>(&json).unwrap();
        let extended = Channel::Other(String::from("Extended"));

        assert_that!(data.canary()).is_none();
        assert_that!(data.channel(&extended))
            .is_some()
            .derive(|it| it.channel.clone())
            .is_equal_to(extended);
    }
}