Skip to content

Commit

Permalink
Merge pull request #15 from peridio/ENG-1221
Browse files Browse the repository at this point in the history
Granular Bundles
  • Loading branch information
nicolasgaviria authored Dec 15, 2023
2 parents 22c4927 + b08f5ba commit 3cdf607
Show file tree
Hide file tree
Showing 4 changed files with 143 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/api/binaries.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ pub struct Binary {
pub organization_prn: String,
pub prn: String,
pub inserted_at: String,
pub revision: u32,
pub signatures: Option<Vec<BinarySignature>>,
pub size: Option<u64>,
pub state: BinaryState,
Expand Down
112 changes: 112 additions & 0 deletions tests/binaries.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
mod common;

use common::API_KEY;
use mockito::{mock, server_url as mock_server_url};

use peridio_sdk::api::binaries::{CreateBinaryParams, GetBinaryParams};

use peridio_sdk::api::Api;
use peridio_sdk::api::ApiOptions;

#[tokio::test]
async fn create_binary() {
let expected_artifact_version_prn = "artifact_version_prn";
let expected_description = "description";
let expected_hash = "hash";
let expected_organization_prn = "organization_prn";
let expected_size = 10;
let expected_target = "target";

let api = Api::new(ApiOptions {
api_key: API_KEY.into(),
endpoint: Some(mock_server_url()),
ca_bundle_path: None,
});

let m = mock("POST", &*format!("/binaries"))
.with_status(201)
.with_header("content-type", "application/json")
.with_body_from_file("tests/fixtures/binaries-create-201.json")
.create();

let params = CreateBinaryParams {
artifact_version_prn: expected_artifact_version_prn.to_string(),
description: Some(expected_description.to_string()),
hash: expected_hash.to_string(),
size: expected_size,
target: expected_target.to_string(),
};

match api.binaries().create(params).await.unwrap() {
Some(binary) => {
assert_eq!(
binary.binary.artifact_version_prn,
expected_artifact_version_prn.to_string()
);
assert_eq!(
binary.binary.description,
Some(expected_description.to_string())
);
assert_eq!(binary.binary.hash, Some(expected_hash.to_string()));
assert_eq!(
binary.binary.organization_prn,
expected_organization_prn.to_string()
);
assert_eq!(binary.binary.size, Some(expected_size));
assert_eq!(binary.binary.target, expected_target.to_string());
}
_ => panic!(),
}

m.assert();
}

#[tokio::test]
async fn get_binary() {
let expected_prn = "prn";
let expected_artifact_version_prn = "artifact_version_prn";
let expected_description = "description";
let expected_hash = "hash";
let expected_organization_prn = "organization_prn";
let expected_size = 10;
let expected_target = "target";

let api = Api::new(ApiOptions {
api_key: API_KEY.into(),
endpoint: Some(mock_server_url()),
ca_bundle_path: None,
});

let m = mock("GET", &*format!("/binaries/{expected_prn}"))
.with_status(200)
.with_header("content-type", "application/json")
.with_body_from_file("tests/fixtures/binaries-get-200.json")
.create();

let params = GetBinaryParams {
prn: expected_prn.to_string(),
};

match api.binaries().get(params).await.unwrap() {
Some(binary) => {
assert_eq!(
binary.binary.artifact_version_prn,
expected_artifact_version_prn.to_string()
);
assert_eq!(
binary.binary.description,
Some(expected_description.to_string())
);
assert_eq!(binary.binary.hash, Some(expected_hash.to_string()));
assert_eq!(
binary.binary.organization_prn,
expected_organization_prn.to_string()
);
assert_eq!(binary.binary.size, Some(expected_size));
assert_eq!(binary.binary.target, expected_target.to_string());
}
_ => panic!(),
}

m.assert();
}
15 changes: 15 additions & 0 deletions tests/fixtures/binaries-create-201.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"binary": {
"artifact_version_prn": "artifact_version_prn",
"description": "description",
"hash": "hash",
"organization_prn": "organization_prn",
"prn": "prn",
"inserted_at": "2000-01-01T00:00:00Z",
"revision": 0,
"size": 10,
"state": "uploadable",
"target": "target",
"updated_at": "2000-01-01T00:00:00Z"
}
}
15 changes: 15 additions & 0 deletions tests/fixtures/binaries-get-200.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"binary": {
"artifact_version_prn": "artifact_version_prn",
"description": "description",
"hash": "hash",
"organization_prn": "organization_prn",
"prn": "prn",
"inserted_at": "2000-01-01T00:00:00Z",
"revision": 0,
"size": 10,
"state": "uploadable",
"target": "target",
"updated_at": "2000-01-01T00:00:00Z"
}
}

0 comments on commit 3cdf607

Please sign in to comment.