• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

CHE3MZ / octorun / 46169632073

28 Nov 2026 05:16PM UTC coverage: 95.162% (+0.2%) from 94.948%
46169632073

push

github

CHE3MZ
chore: release v1.3.0

3147 of 3307 relevant lines covered (95.16%)

4.77 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

95.03
/src/github/api.rs
1
//! A small GitHub REST client for runner operations.
2

3
use std::thread;
4
use std::time::Duration;
5

6
use reqwest::StatusCode;
7
use reqwest::blocking::{Client as HttpClient, RequestBuilder, Response};
8
use reqwest::header::{ACCEPT, AUTHORIZATION, RETRY_AFTER};
9
use serde::Deserialize;
10
use serde::de::DeserializeOwned;
11

12
use crate::error::{Error, Result};
13

14
const API_VERSION: &str = "2022-11-28";
15
const ACCEPT_JSON: &str = "application/vnd.github+json";
16
const MAX_ATTEMPTS: u32 = 3;
17
const BACKOFF: Duration = Duration::from_millis(200);
18

19
/// The scope a runner is registered in.
20
#[derive(Debug, Clone, PartialEq, Eq)]
21
#[non_exhaustive]
22
pub enum Scope {
23
    /// A single repository.
24
    Repository {
25
        /// Repository owner.
26
        owner: String,
27
        /// Repository name.
28
        name: String,
29
    },
30
    /// An organization.
31
    Organization(String),
32
    /// An enterprise.
33
    Enterprise(String),
34
}
35

36
impl Scope {
37
    fn path(&self) -> String {
11 ✔
38
        match self {
11 ✔
39
            Self::Repository { owner, name } => format!("repos/{owner}/{name}"),
5 ✔
40
            Self::Organization(organization) => format!("orgs/{organization}"),
5 ✔
41
            Self::Enterprise(enterprise) => format!("enterprises/{enterprise}"),
1 ✔
42
        }
43
    }
11 ✔
44
}
45

46
/// The kind of runner token to request.
47
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
48
#[non_exhaustive]
49
pub enum TokenKind {
50
    /// Token used to register a new runner.
51
    Registration,
52
    /// Token used to remove an existing runner.
53
    Remove,
54
}
55

56
impl TokenKind {
57
    fn path(self) -> &'static str {
10 ✔
58
        match self {
10 ✔
59
            Self::Registration => "registration-token",
8 ✔
60
            Self::Remove => "remove-token",
2 ✔
61
        }
62
    }
10 ✔
63
}
64

65
/// The latest release of the `actions/runner` repository.
66
#[derive(Debug, Clone, Deserialize)]
67
#[non_exhaustive]
68
pub struct Release {
69
    /// The release tag, e.g. `v2.300.0`.
70
    #[serde(rename = "tag_name")]
71
    pub tag_name: String,
72
    /// Assets attached to the release.
73
    #[serde(default)]
74
    pub assets: Vec<ReleaseAsset>,
75
}
76

77
/// A release asset, including its GitHub-published digest.
78
#[derive(Debug, Clone, Deserialize)]
79
#[non_exhaustive]
80
pub struct ReleaseAsset {
81
    /// Asset file name.
82
    pub name: String,
83
    /// Digest in the form `sha256:<hex>`, when GitHub provides one.
84
    pub digest: Option<String>,
85
    /// URL used to download the asset.
86
    pub browser_download_url: String,
87
}
88

89
impl Release {
90
    /// The tag with any leading `v` removed.
91
    #[must_use]
92
    pub fn version(&self) -> &str {
5 ✔
93
        self.tag_name.trim_start_matches('v')
5 ✔
94
    }
5 ✔
95

96
    /// Find an asset by file name.
97
    #[must_use]
98
    pub fn asset(&self, name: &str) -> Option<&ReleaseAsset> {
3 ✔
99
        self.assets.iter().find(|asset| asset.name == name)
3 ✔
100
    }
3 ✔
101
}
102

103
/// GitHub REST client used for runner operations.
104
pub struct Client {
105
    http: HttpClient,
106
    base_url: String,
107
    tokens: Vec<String>,
108
}
109

110
impl Client {
111
    /// Create a client for `host` with a single token.
112
    ///
113
    /// # Errors
114
    ///
115
    /// Returns an error if the HTTP client cannot be built.
116
    pub fn new(host: &str, token: impl Into<String>) -> Result<Self> {
1 ✔
117
        Self::with_tokens(host, vec![token.into()])
1 ✔
118
    }
1 ✔
119

120
    /// Create a client for `host` with tokens to try in order.
121
    ///
122
    /// `github.com` uses the public API. Any other host is treated as a GitHub
123
    /// Enterprise instance served from `/api/v3`.
124
    ///
125
    /// # Errors
126
    ///
127
    /// Returns [`Error::MissingToken`] for an empty token list, or an error if
128
    /// the HTTP client cannot be built.
129
    pub fn with_tokens(host: &str, tokens: Vec<String>) -> Result<Self> {
2 ✔
130
        let base_url = if host == "github.com" {
2 ✔
131
            "https://api.github.com".to_owned()
1 ✔
132
        } else {
133
            format!("https://{host}/api/v3")
1 ✔
134
        };
135
        Self::with_base_urls(base_url, tokens)
2 ✔
136
    }
2 ✔
137

138
    /// Create a client with an explicit API base URL and a single token.
139
    ///
140
    /// # Errors
141
    ///
142
    /// Returns an error if the HTTP client cannot be built.
143
    pub fn with_base_url(base_url: impl Into<String>, token: impl Into<String>) -> Result<Self> {
17 ✔
144
        Self::with_base_urls(base_url, vec![token.into()])
17 ✔
145
    }
17 ✔
146

147
    /// Create a client with an explicit API base URL and tokens to try in order.
148
    ///
149
    /// # Errors
150
    ///
151
    /// Returns [`Error::MissingToken`] for an empty token list, or an error if
152
    /// the HTTP client cannot be built.
153
    pub fn with_base_urls(base_url: impl Into<String>, tokens: Vec<String>) -> Result<Self> {
22 ✔
154
        if tokens.is_empty() {
22 ✔
155
            return Err(Error::MissingToken);
1 ✔
156
        }
21 ✔
157
        Self::build(base_url, tokens)
21 ✔
158
    }
22 ✔
159

160
    /// Create a client that sends no token.
161
    ///
162
    /// Public endpoints such as the `actions/runner` releases accept anonymous
163
    /// requests.
164
    ///
165
    /// # Errors
166
    ///
167
    /// Returns an error if the HTTP client cannot be built.
168
    pub fn anonymous(host: &str) -> Result<Self> {
4 ✔
169
        let base_url = if host == "github.com" {
4 ✔
170
            "https://api.github.com".to_owned()
3 ✔
171
        } else {
172
            format!("https://{host}/api/v3")
1 ✔
173
        };
174
        Self::build(base_url, Vec::new())
4 ✔
175
    }
4 ✔
176

177
    fn build(base_url: impl Into<String>, tokens: Vec<String>) -> Result<Self> {
26 ✔
178
        let http = HttpClient::builder()
26 ✔
179
            .user_agent(concat!("octorun/", env!("CARGO_PKG_VERSION")))
26 ✔
180
            .timeout(Duration::from_secs(30))
26 ✔
181
            .build()?;
26 ✔
182

183
        Ok(Self {
26 ✔
184
            http,
26 ✔
185
            base_url: base_url.into().trim_end_matches('/').to_owned(),
26 ✔
186
            tokens,
26 ✔
187
        })
26 ✔
188
    }
26 ✔
189

190
    /// Fetch the latest `actions/runner` release.
191
    ///
192
    /// # Errors
193
    ///
194
    /// Returns an error if the request fails or the response is not successful.
195
    pub fn latest_runner_release(&self) -> Result<Release> {
7 ✔
196
        let base = &self.base_url;
7 ✔
197
        let url = format!("{base}/repos/actions/runner/releases/latest");
7 ✔
198
        self.send(|token| Self::authorized(self.http.get(url.clone()), token))
10 ✔
199
    }
7 ✔
200

201
    /// Request a runner token for `scope`.
202
    ///
203
    /// # Errors
204
    ///
205
    /// Returns an error if the request fails, the response is not successful,
206
    /// or the returned token is empty.
207
    pub fn runner_token(&self, scope: &Scope, kind: TokenKind) -> Result<String> {
8 ✔
208
        #[derive(Deserialize)]
209
        struct Token {
210
            token: String,
211
        }
212

213
        let base = &self.base_url;
8 ✔
214
        let scope = scope.path();
8 ✔
215
        let kind = kind.path();
8 ✔
216
        let url = format!("{base}/{scope}/actions/runners/{kind}");
8 ✔
217
        let body = serde_json::json!({});
8 ✔
218

219
        let Token { token } =
220
            self.send(|token| Self::authorized(self.http.post(url.clone()).json(&body), token))?;
8 ✔
221

222
        if token.is_empty() {
8 ✔
223
            return Err(Error::Api(
1 ✔
224
                "GitHub returned an empty runner token".to_owned(),
1 ✔
225
            ));
1 ✔
226
        }
7 ✔
227
        Ok(token)
7 ✔
228
    }
8 ✔
229

230
    fn send<T: DeserializeOwned>(
15 ✔
231
        &self,
15 ✔
232
        build: impl Fn(Option<&str>) -> RequestBuilder,
15 ✔
233
    ) -> Result<T> {
15 ✔
234
        if self.tokens.is_empty() {
15 ✔
235
            return decode(Self::send_with_retries(|| build(None))?);
1 ✔
236
        }
14 ✔
237

238
        let mut last_unauthorized = None;
14 ✔
239

240
        for token in &self.tokens {
14 ✔
241
            let response = Self::send_with_retries(|| build(Some(token)))?;
17 ✔
242
            if response.status() == StatusCode::UNAUTHORIZED {
16 ✔
243
                tracing::debug!("GitHub rejected a token, trying the next one");
3 ✔
244
                last_unauthorized = Some(response);
3 ✔
245
                continue;
3 ✔
246
            }
13 ✔
247
            return decode(response);
13 ✔
248
        }
249

250
        match last_unauthorized {
1 ✔
251
            Some(response) => decode(response),
1 ✔
252
            None => Err(Error::MissingToken),
×
253
        }
254
    }
15 ✔
255

256
    fn send_with_retries(build: impl Fn() -> RequestBuilder) -> Result<Response> {
17 ✔
257
        let mut attempt = 0;
17 ✔
258
        loop {
259
            attempt += 1;
18 ✔
260
            match build().send() {
18 ✔
261
                Ok(response) => {
262
                    if is_retryable_status(response.status()) && attempt < MAX_ATTEMPTS {
18 ✔
263
                        let delay = retry_delay(&response, attempt);
1 ✔
264
                        tracing::debug!("retrying GitHub request after {delay:?}");
1 ✔
265
                        drop(response);
1 ✔
266
                        thread::sleep(delay);
1 ✔
267
                    } else {
268
                        return Ok(response);
17 ✔
269
                    }
270
                }
271
                Err(error) if retryable_transport(&error) && attempt < MAX_ATTEMPTS => {
×
272
                    let delay = backoff(attempt);
×
273
                    tracing::debug!("retrying GitHub request after {delay:?}: {error}");
×
274
                    thread::sleep(delay);
×
275
                }
276
                Err(error) => return Err(error.into()),
×
277
            }
278
        }
279
    }
17 ✔
280

281
    fn authorized(request: RequestBuilder, token: Option<&str>) -> RequestBuilder {
18 ✔
282
        let request = request
18 ✔
283
            .header(ACCEPT, ACCEPT_JSON)
18 ✔
284
            .header("X-GitHub-Api-Version", API_VERSION);
18 ✔
285
        match token {
18 ✔
286
            Some(token) => request.header(AUTHORIZATION, format!("Bearer {token}")),
17 ✔
287
            None => request,
1 ✔
288
        }
289
    }
18 ✔
290
}
291

292
fn is_retryable_status(status: StatusCode) -> bool {
18 ✔
293
    status == StatusCode::TOO_MANY_REQUESTS || status.is_server_error()
18 ✔
294
}
18 ✔
295

296
fn retryable_transport(error: &reqwest::Error) -> bool {
×
297
    error.is_timeout() || error.is_connect() || error.is_request()
×
298
}
×
299

300
fn backoff(attempt: u32) -> Duration {
1 ✔
301
    BACKOFF.saturating_mul(attempt)
1 ✔
302
}
1 ✔
303

304
fn retry_delay(response: &Response, attempt: u32) -> Duration {
1 ✔
305
    response
1 ✔
306
        .headers()
1 ✔
307
        .get(RETRY_AFTER)
1 ✔
308
        .and_then(|value| value.to_str().ok())
×
309
        .and_then(|value| value.trim().parse::<u64>().ok())
×
310
        .map_or_else(
311
            || backoff(attempt),
1 ✔
312
            |seconds| Duration::from_secs(seconds.min(5)),
×
313
        )
314
}
1 ✔
315

316
fn decode<T: DeserializeOwned>(response: Response) -> Result<T> {
15 ✔
317
    let status = response.status();
15 ✔
318
    if !status.is_success() {
15 ✔
319
        let code = status.as_u16();
2 ✔
320
        let body = response.text().unwrap_or_default();
2 ✔
321
        let body = body.trim();
2 ✔
322
        return Err(Error::Api(format!(
2 ✔
323
            "request failed with status {code}: {body}"
2 ✔
324
        )));
2 ✔
325
    }
13 ✔
326
    Ok(response.json()?)
13 ✔
327
}
15 ✔
328

329
#[cfg(test)]
330
mod tests {
331
    use std::io::{Read, Write};
332
    use std::net::{TcpListener, TcpStream};
333
    use std::thread::JoinHandle;
334

335
    use super::{Client, Release, Scope, TokenKind};
336
    use crate::error::Error;
337

338
    fn serve_sequence(responses: Vec<(&'static str, String)>) -> (String, JoinHandle<Vec<String>>) {
8 ✔
339
        let listener = TcpListener::bind("127.0.0.1:0").unwrap();
8 ✔
340
        let address = listener.local_addr().unwrap();
8 ✔
341

342
        let handle = std::thread::spawn(move || {
8 ✔
343
            let mut requests = Vec::new();
8 ✔
344
            for (status, body) in responses {
8 ✔
345
                let (mut stream, _) = listener.accept().unwrap();
11 ✔
346
                let request = read_request(&mut stream);
11 ✔
347
                requests.push(String::from_utf8_lossy(&request).into_owned());
11 ✔
348

349
                let response = format!(
11 ✔
350
                    "HTTP/1.1 {status}\r\nContent-Type: application/json\r\nContent-Length: {}\r\nConnection: close\r\n\r\n{body}",
11 ✔
351
                    body.len()
11 ✔
352
                );
353
                stream.write_all(response.as_bytes()).unwrap();
11 ✔
354
                stream.flush().unwrap();
11 ✔
355
            }
356
            requests
8 ✔
357
        });
8 ✔
358

359
        (format!("http://{address}"), handle)
8 ✔
360
    }
8 ✔
361

362
    fn serve_once(status: &'static str, body: &str) -> (String, JoinHandle<Vec<String>>) {
5 ✔
363
        serve_sequence(vec![(status, body.to_owned())])
5 ✔
364
    }
5 ✔
365

366
    fn read_request(stream: &mut TcpStream) -> Vec<u8> {
11 ✔
367
        let mut data = Vec::new();
11 ✔
368
        let mut buffer = [0_u8; 1024];
11 ✔
369

370
        loop {
371
            let read = match stream.read(&mut buffer) {
11 ✔
372
                Ok(0) | Err(_) => break,
×
373
                Ok(read) => read,
11 ✔
374
            };
375
            data.extend_from_slice(&buffer[..read]);
11 ✔
376

377
            if let Some(header_end) = data.windows(4).position(|window| window == b"\r\n\r\n") {
2,302 ✔
378
                let header_len = header_end + 4;
11 ✔
379
                let headers = String::from_utf8_lossy(&data[..header_end]).to_ascii_lowercase();
11 ✔
380
                let content_length = headers
11 ✔
381
                    .lines()
11 ✔
382
                    .find_map(|line| line.strip_prefix("content-length:"))
65 ✔
383
                    .and_then(|value| value.trim().parse::<usize>().ok())
2 ✔
384
                    .unwrap_or(0);
11 ✔
385
                if data.len() >= header_len + content_length {
11 ✔
386
                    break;
11 ✔
387
                }
×
388
            }
×
389
        }
390

391
        data
11 ✔
392
    }
11 ✔
393

394
    #[test]
395
    fn fetches_latest_runner_release() {
1 ✔
396
        let (base, server) = serve_once("200 OK", r#"{"tag_name":"v2.300.0"}"#);
1 ✔
397
        let client = Client::with_base_url(base, "secret").unwrap();
1 ✔
398

399
        let release = client.latest_runner_release().unwrap();
1 ✔
400
        let requests = server.join().unwrap();
1 ✔
401
        let request = &requests[0];
1 ✔
402

403
        assert_eq!(release.version(), "2.300.0");
1 ✔
404
        assert!(request.starts_with("GET /repos/actions/runner/releases/latest "));
1 ✔
405
        assert!(
1 ✔
406
            request
1 ✔
407
                .to_ascii_lowercase()
1 ✔
408
                .contains("authorization: bearer secret")
1 ✔
409
        );
410
    }
1 ✔
411

412
    #[test]
413
    fn anonymous_client_omits_authorization() {
1 ✔
414
        let (base, server) = serve_once("200 OK", r#"{"tag_name":"v2.300.0"}"#);
1 ✔
415
        let client = Client::build(base, Vec::new()).unwrap();
1 ✔
416

417
        let release = client.latest_runner_release().unwrap();
1 ✔
418
        let requests = server.join().unwrap();
1 ✔
419

420
        assert_eq!(release.version(), "2.300.0");
1 ✔
421
        assert!(!requests[0].to_ascii_lowercase().contains("authorization"));
1 ✔
422
    }
1 ✔
423

424
    #[test]
425
    fn requests_repository_registration_token() {
1 ✔
426
        let (base, server) = serve_once("200 OK", r#"{"token":"runner-token"}"#);
1 ✔
427
        let client = Client::with_base_url(base, "secret").unwrap();
1 ✔
428
        let scope = Scope::Repository {
1 ✔
429
            owner: "acme".to_owned(),
1 ✔
430
            name: "app".to_owned(),
1 ✔
431
        };
1 ✔
432

433
        let token = client
1 ✔
434
            .runner_token(&scope, TokenKind::Registration)
1 ✔
435
            .unwrap();
1 ✔
436
        let requests = server.join().unwrap();
1 ✔
437
        let request = &requests[0];
1 ✔
438

439
        assert_eq!(token, "runner-token");
1 ✔
440
        assert!(request.starts_with("POST /repos/acme/app/actions/runners/registration-token "));
1 ✔
441
    }
1 ✔
442

443
    #[test]
444
    fn reports_api_errors() {
1 ✔
445
        let (base, server) = serve_once("403 Forbidden", r#"{"message":"forbidden"}"#);
1 ✔
446
        let client = Client::with_base_url(base, "secret").unwrap();
1 ✔
447

448
        let error = client.latest_runner_release().unwrap_err();
1 ✔
449
        server.join().unwrap();
1 ✔
450

451
        match error {
1 ✔
452
            Error::Api(message) => {
453
                assert!(message.contains("403") && message.contains("forbidden"));
1 ✔
454
            }
455
            other => panic!("expected api error, got {other:?}"),
×
456
        }
457
    }
1 ✔
458

459
    #[test]
460
    fn retries_server_errors() {
1 ✔
461
        let (base, server) = serve_sequence(vec![
1 ✔
462
            ("500 Internal Server Error", "try again".to_owned()),
1 ✔
463
            ("200 OK", r#"{"tag_name":"v2.300.0"}"#.to_owned()),
1 ✔
464
        ]);
1 ✔
465
        let client = Client::with_base_url(base, "secret").unwrap();
1 ✔
466

467
        let release = client.latest_runner_release().unwrap();
1 ✔
468
        let requests = server.join().unwrap();
1 ✔
469

470
        assert_eq!(release.version(), "2.300.0");
1 ✔
471
        assert_eq!(requests.len(), 2);
1 ✔
472
    }
1 ✔
473

474
    #[test]
475
    fn falls_back_to_the_next_token() {
1 ✔
476
        let (base, server) = serve_sequence(vec![
1 ✔
477
            (
1 ✔
478
                "401 Unauthorized",
1 ✔
479
                r#"{"message":"bad credentials"}"#.to_owned(),
1 ✔
480
            ),
1 ✔
481
            ("200 OK", r#"{"tag_name":"v2.300.0"}"#.to_owned()),
1 ✔
482
        ]);
1 ✔
483
        let client =
484
            Client::with_base_urls(base, vec!["bad".to_owned(), "good".to_owned()]).unwrap();
1 ✔
485

486
        let release = client.latest_runner_release().unwrap();
1 ✔
487
        let requests = server.join().unwrap();
1 ✔
488

489
        assert_eq!(release.version(), "2.300.0");
1 ✔
490
        assert!(
1 ✔
491
            requests[0]
1 ✔
492
                .to_ascii_lowercase()
1 ✔
493
                .contains("authorization: bearer bad")
1 ✔
494
        );
495
        assert!(
1 ✔
496
            requests[1]
1 ✔
497
                .to_ascii_lowercase()
1 ✔
498
                .contains("authorization: bearer good")
1 ✔
499
        );
500
    }
1 ✔
501

502
    #[test]
503
    fn finds_release_assets() {
1 ✔
504
        let release: Release = serde_json::from_str(
1 ✔
505
            r#"{"tag_name":"v1","assets":[{"name":"runner.zip","digest":"sha256:abc","browser_download_url":"https://example.com/runner.zip"}]}"#,
1 ✔
506
        )
1 ✔
507
        .unwrap();
1 ✔
508

509
        assert_eq!(
1 ✔
510
            release.asset("runner.zip").unwrap().digest.as_deref(),
1 ✔
511
            Some("sha256:abc")
1 ✔
512
        );
513
        assert!(release.asset("missing.zip").is_none());
1 ✔
514
    }
1 ✔
515

516
    #[test]
517
    fn builds_scope_paths() {
1 ✔
518
        assert_eq!(
1 ✔
519
            Scope::Repository {
1 ✔
520
                owner: "acme".to_owned(),
1 ✔
521
                name: "app".to_owned(),
1 ✔
522
            }
1 ✔
523
            .path(),
1 ✔
524
            "repos/acme/app"
1 ✔
525
        );
526
        assert_eq!(Scope::Organization("acme".to_owned()).path(), "orgs/acme");
1 ✔
527
        assert_eq!(
1 ✔
528
            Scope::Enterprise("acme".to_owned()).path(),
1 ✔
529
            "enterprises/acme"
1 ✔
530
        );
531
    }
1 ✔
532

533
    #[test]
534
    fn builds_token_kinds() {
1 ✔
535
        assert_eq!(TokenKind::Registration.path(), "registration-token");
1 ✔
536
        assert_eq!(TokenKind::Remove.path(), "remove-token");
1 ✔
537
    }
1 ✔
538

539
    #[test]
540
    fn requires_at_least_one_token() {
1 ✔
541
        assert!(matches!(
1 ✔
542
            Client::with_base_urls("http://localhost", Vec::new()),
1 ✔
543
            Err(Error::MissingToken)
544
        ));
545
    }
1 ✔
546

547
    #[test]
548
    fn builds_authenticated_and_anonymous_clients() {
1 ✔
549
        assert!(Client::new("github.com", "token").is_ok());
1 ✔
550
        assert!(Client::with_tokens("github.example.com", vec!["token".to_owned()]).is_ok());
1 ✔
551
        assert!(Client::with_base_url("http://localhost", "token").is_ok());
1 ✔
552
        assert!(Client::anonymous("github.com").is_ok());
1 ✔
553
        assert!(Client::anonymous("github.example.com").is_ok());
1 ✔
554
    }
1 ✔
555

556
    #[test]
557
    fn rejects_empty_runner_tokens() {
1 ✔
558
        let (base, server) = serve_once("200 OK", r#"{"token":""}"#);
1 ✔
559
        let client = Client::with_base_url(base, "secret").unwrap();
1 ✔
560
        let scope = Scope::Organization("acme".to_owned());
1 ✔
561

562
        let error = client
1 ✔
563
            .runner_token(&scope, TokenKind::Registration)
1 ✔
564
            .unwrap_err();
1 ✔
565
        server.join().unwrap();
1 ✔
566

567
        assert!(matches!(error, Error::Api(message) if message.contains("empty")));
1 ✔
568
    }
1 ✔
569

570
    #[test]
571
    fn reports_when_every_token_is_rejected() {
1 ✔
572
        let (base, server) = serve_sequence(vec![
1 ✔
573
            ("401 Unauthorized", r#"{"message":"bad"}"#.to_owned()),
1 ✔
574
            ("401 Unauthorized", r#"{"message":"bad"}"#.to_owned()),
1 ✔
575
        ]);
1 ✔
576
        let client = Client::with_base_urls(base, vec!["a".to_owned(), "b".to_owned()]).unwrap();
1 ✔
577

578
        let error = client.latest_runner_release().unwrap_err();
1 ✔
579
        server.join().unwrap();
1 ✔
580

581
        assert!(matches!(error, Error::Api(_)));
1 ✔
582
    }
1 ✔
583
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE TRIAL · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc