Skip to content

Commit

Permalink
tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
quettabit committed Jun 21, 2022
1 parent ce64806 commit 38b0fa6
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/v1/objects.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
//! Types and APIs for interacting with GCS [Objects](https://cloud.google.com/storage/docs/json_api/v1/objects)
use crate::common::StorageClass;
use http::uri::Authority;
use std::collections::BTreeMap;

#[doc(hidden)]
Expand All @@ -27,7 +28,6 @@ mod rewrite;
pub use delete::*;
pub use download::*;
pub use get::*;
use http::uri::Authority;
pub use insert::*;
pub use list::*;
pub use patch::*;
Expand All @@ -37,6 +37,8 @@ pub type Timestamp = time::OffsetDateTime;

/// Helper struct used to collate all of the operations available for
/// [Objects](https://cloud.google.com/storage/docs/json_api/v1/objects)
/// Additionally, it can also be used to specify a custom authority.
#[derive(Debug)]
pub struct Object {
authority: Authority,
}
Expand Down
44 changes: 44 additions & 0 deletions tests/objects.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use http::uri::Authority;
use tame_gcs::{
common::{Conditionals, StandardQueryParameters},
objects::{self, DeleteObjectOptional, InsertObjectOptional, Metadata, Object},
Expand Down Expand Up @@ -31,6 +32,31 @@ fn insert_vanilla() {
util::requests_eq(&insert_req, &expected);
}

#[test]
fn insert_vanilla_using_custom_authority() {
let insert_req = Object::with_authority(Authority::from_static("0.0.0.0:4443"))
.insert_simple(
&(
&BucketName::non_validated("bucket"),
&ObjectName::non_validated("object/with/deep/path"),
),
"great content",
13,
None,
)
.unwrap();

let expected = http::Request::builder()
.method(http::Method::POST)
.uri("https://0.0.0.0:4443/upload/storage/v1/b/bucket/o?name=object/with/deep/path&uploadType=media&prettyPrint=false")
.header(http::header::CONTENT_TYPE, "application/octet-stream")
.header(http::header::CONTENT_LENGTH, 13)
.body("great content")
.unwrap();

util::requests_eq(&insert_req, &expected);
}

#[test]
fn insert_json_content() {
let insert_req = Object::default()
Expand Down Expand Up @@ -75,6 +101,24 @@ fn vanilla_get() {
util::requests_eq(&get_req, &expected);
}

#[test]
fn vanilla_get_using_custom_authority() {
let get_req = Object::with_authority(Authority::from_static("0.0.0.0:4443"))
.get(
&ObjectId::new("bucket", "test/with/path_separators").unwrap(),
None,
)
.unwrap();

let expected = http::Request::builder()
.method(http::Method::GET)
.uri("https://0.0.0.0:4443/storage/v1/b/bucket/o/test%2Fwith%2Fpath_separators?alt=json&prettyPrint=false")
.body(std::io::empty())
.unwrap();

util::requests_eq(&get_req, &expected);
}

#[test]
fn delete_vanilla() {
let delete_req = Object::default()
Expand Down

0 comments on commit 38b0fa6

Please sign in to comment.