Skip to main content

taskcluster_download/
service.rs

1//! Trait wrappers around Taskcluster types to allow fake injection during tests.
2use anyhow::Error;
3use async_trait::async_trait;
4use serde_json::Value;
5use taskcluster::{Object, Queue};
6
7/// A private wrapper around the necessary methods of the object service.
8#[allow(non_snake_case)]
9#[async_trait]
10pub(super) trait ObjectService {
11    async fn startDownload(&self, name: &str, payload: &Value)
12        -> std::result::Result<Value, Error>;
13}
14
15/// Trivial implementation of the ObjectService trait for the Object client struct
16#[async_trait]
17impl ObjectService for Object {
18    async fn startDownload(
19        &self,
20        name: &str,
21        payload: &Value,
22    ) -> std::result::Result<Value, Error> {
23        (self as &Object).startDownload(name, payload).await
24    }
25}
26
27/// A private wrapper around the necessary methods of the object service.
28#[allow(non_snake_case)]
29#[async_trait]
30pub(super) trait QueueService {
31    async fn artifact(
32        &self,
33        task_id: &str,
34        run_id: &str,
35        name: &str,
36    ) -> std::result::Result<Value, Error>;
37    async fn latestArtifact(&self, task_id: &str, name: &str) -> std::result::Result<Value, Error>;
38}
39
40/// Trivial implementation of the QueueService trait for the Queue client struct
41#[async_trait]
42impl QueueService for Queue {
43    async fn artifact(
44        &self,
45        task_id: &str,
46        run_id: &str,
47        name: &str,
48    ) -> std::result::Result<Value, Error> {
49        (self as &Queue).artifact(task_id, run_id, name).await
50    }
51
52    async fn latestArtifact(&self, task_id: &str, name: &str) -> std::result::Result<Value, Error> {
53        (self as &Queue).latestArtifact(task_id, name).await
54    }
55}