Skip to content

Commit

Permalink
Merge pull request #33 from peridio/spoff/eng-3152-peridio-rust-bump-…
Browse files Browse the repository at this point in the history
…mockito

bump mockito
  • Loading branch information
danielspofford authored Aug 22, 2024
2 parents 22c50d4 + 6ea2787 commit 18a754c
Show file tree
Hide file tree
Showing 21 changed files with 740 additions and 510 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,4 @@ validator = { version = "0.18.1", features = ["derive"] }


[dev-dependencies]
mockito = "0.31"
mockito = "1.5.0"
47 changes: 30 additions & 17 deletions tests/artifact_versions.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
mod common;

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

use peridio_sdk::api::artifact_versions::{
CreateArtifactVersionParams, GetArtifactVersionParams, UpdateArtifactVersionParams,
Expand All @@ -13,22 +13,25 @@ use serde_json::json;

#[tokio::test]
async fn create_artifact_version() {
let mut server = Server::new_async().await;
let expected_artifact_prn = "artifact_prn";
let expected_custom_metadata = json!({ "foo": "bar" });
let expected_description = "description";
let expected_version = "v0.0.1";

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

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

let params = CreateArtifactVersionParams {
artifact_prn: expected_artifact_prn.to_string(),
Expand Down Expand Up @@ -59,15 +62,17 @@ async fn create_artifact_version() {
_ => panic!(),
}

m.assert();
m.assert_async().await;

let expected_custom_metadata = json!({ "foo": "a".repeat(1_000_000 ) });

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

let params = CreateArtifactVersionParams {
artifact_prn: expected_artifact_prn.to_string(),
Expand All @@ -88,22 +93,25 @@ async fn create_artifact_version() {

#[tokio::test]
async fn get_artifact_version() {
let mut server = Server::new_async().await;
let expected_prn = "prn";
let expected_artifact_prn = "artifact_prn";
let expected_description = "description";
let expected_version = "v0.0.1";

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

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

let params = GetArtifactVersionParams {
prn: expected_prn.to_string(),
Expand All @@ -127,26 +135,29 @@ async fn get_artifact_version() {
_ => panic!(),
}

m.assert();
m.assert_async().await;
}

#[tokio::test]
async fn update_artifact() {
let mut server = Server::new_async().await;
let expected_prn = "prn";
let expected_custom_metadata = json!({ "foo": "bar" });
let expected_description = "updated_description";

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

let m = mock("PATCH", &*format!("/artifact_versions/{expected_prn}"))
let m = server
.mock("PATCH", &*format!("/artifact_versions/{expected_prn}"))
.with_status(200)
.with_header("content-type", "application/json")
.with_body_from_file("tests/fixtures/artifact-versions-update-200.json")
.create();
.create_async()
.await;

let params = UpdateArtifactVersionParams {
prn: expected_prn.to_string(),
Expand All @@ -168,15 +179,17 @@ async fn update_artifact() {
_ => panic!(),
}

m.assert();
m.assert_async().await;

let expected_custom_metadata = json!({ "foo": "a".repeat(1_000_000 ) });

let m = mock("PATCH", &*format!("/artifact_versions/{expected_prn}"))
let m = server
.mock("PATCH", &*format!("/artifact_versions/{expected_prn}"))
.with_status(200)
.with_header("content-type", "application/json")
.with_body_from_file("tests/fixtures/artifact-versions-update-200.json")
.create();
.create_async()
.await;

let params = UpdateArtifactVersionParams {
prn: expected_prn.to_string(),
Expand Down
47 changes: 30 additions & 17 deletions tests/artifacts.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
mod common;

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

use peridio_sdk::api::artifacts::{CreateArtifactParams, GetArtifactParams, UpdateArtifactParams};

Expand All @@ -10,22 +10,25 @@ use serde_json::json;

#[tokio::test]
async fn create_artifact() {
let mut server = Server::new_async().await;
let expected_custom_metadata = json!({ "foo": "bar" });
let expected_description = "test";
let expected_name = "a";
let expected_organization_prn = "string";

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

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

let params = CreateArtifactParams {
custom_metadata: Some(expected_custom_metadata.as_object().unwrap().clone()),
Expand Down Expand Up @@ -53,15 +56,17 @@ async fn create_artifact() {
_ => panic!(),
}

m.assert();
m.assert_async().await;

let expected_custom_metadata = json!({ "foo": "a".repeat(1_000_000 ) });

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

let params = CreateArtifactParams {
custom_metadata: Some(expected_custom_metadata.as_object().unwrap().clone()),
Expand All @@ -82,22 +87,25 @@ async fn create_artifact() {

#[tokio::test]
async fn get_artifact() {
let mut server = Server::new_async().await;
let expected_description = "test";
let expected_name = "a";
let expected_organization_prn = "string";
let expected_prn = "1";

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

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

let params = GetArtifactParams {
prn: expected_prn.to_string(),
Expand All @@ -118,11 +126,12 @@ async fn get_artifact() {
_ => panic!(),
}

m.assert();
m.assert_async().await;
}

#[tokio::test]
async fn update_artifact() {
let mut server = Server::new_async().await;
let expected_custom_metadata = json!({ "foo": "bar" });
let expected_description = "test-update";
let expected_name = "b";
Expand All @@ -131,15 +140,17 @@ async fn update_artifact() {

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

let m = mock("PATCH", &*format!("/artifacts/{expected_prn}"))
let m = server
.mock("PATCH", &*format!("/artifacts/{expected_prn}"))
.with_status(200)
.with_header("content-type", "application/json")
.with_body_from_file("tests/fixtures/artifacts-update-200.json")
.create();
.create_async()
.await;

let params = UpdateArtifactParams {
prn: expected_prn.to_string(),
Expand Down Expand Up @@ -167,15 +178,17 @@ async fn update_artifact() {
_ => panic!(),
}

m.assert();
m.assert_async().await;

let expected_custom_metadata = json!({ "foo": "a".repeat(1_000_000 ) });

let m = mock("PATCH", &*format!("/artifacts/{expected_prn}"))
let m = server
.mock("PATCH", &*format!("/artifacts/{expected_prn}"))
.with_status(200)
.with_header("content-type", "application/json")
.with_body_from_file("tests/fixtures/artifacts-update-200.json")
.create();
.create_async()
.await;

let params = UpdateArtifactParams {
prn: expected_prn.to_string(),
Expand Down
Loading

0 comments on commit 18a754c

Please sign in to comment.