Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

verification-client server implementation #58

Merged
merged 45 commits into from
Oct 27, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
642227f
verification-client server implementation & reading test cases
dansanduleac Oct 25, 2018
c898c9d
authors
dansanduleac Oct 25, 2018
614b339
nearly did something
Oct 25, 2018
f8c6b4d
add zipkin
dansanduleac Oct 25, 2018
5766553
Client errors namespace => ConjureVerificationClient
dansanduleac Oct 25, 2018
e4a2fc4
Make errors client-specific
dansanduleac Oct 25, 2018
b602b45
Implement handle_auto_deserialise_test
dansanduleac Oct 25, 2018
468ee8c
deserialize!
dansanduleac Oct 25, 2018
fdbe523
omg format
dansanduleac Oct 25, 2018
8ade81b
format
dansanduleac Oct 25, 2018
f8c0a96
unused
dansanduleac Oct 25, 2018
8cfd28f
more unused
dansanduleac Oct 25, 2018
a72186b
Fmt remove more stuff
dansanduleac Oct 25, 2018
2e4824a
more final touches
dansanduleac Oct 25, 2018
e01993e
more unused
dansanduleac Oct 25, 2018
62be5cf
log
dansanduleac Oct 25, 2018
780027e
change namespace for default errors
dansanduleac Oct 25, 2018
1e74c6c
expose connection error to user
dansanduleac Oct 26, 2018
c5b2dbe
format
dansanduleac Oct 26, 2018
cdb8d30
fix templating!!!
dansanduleac Oct 26, 2018
732905f
better error when url parse failure and max_num_retries(0)
dansanduleac Oct 26, 2018
297911e
USER_AGENT -> static
dansanduleac Oct 26, 2018
205adba
accept only JSON, we're not testing other wire formats
dansanduleac Oct 26, 2018
6dba4a1
Handle null -> 204 response
dansanduleac Oct 26, 2018
a8b4e93
all empty conjure values -> accept 204
dansanduleac Oct 26, 2018
b1c4ecd
assert content type matches expected types
dansanduleac Oct 26, 2018
e5e9ac8
cargo fmt
dansanduleac Oct 26, 2018
492ce61
remove test macro_use
dansanduleac Oct 26, 2018
0419ab6
Verify that negative test cases get client error back
dansanduleac Oct 26, 2018
74fcf84
factor out check_negative_test_case
dansanduleac Oct 26, 2018
c8c8c68
factor out check_positive_test_case
dansanduleac Oct 26, 2018
3b48af1
spaces
dansanduleac Oct 26, 2018
ef15f5d
use proper UnexpectedResponseCode error
dansanduleac Oct 26, 2018
f567c21
Refactor errors to use FailedPrecondition
dansanduleac Oct 26, 2018
21c699f
add new error CouldNotParseServerResponse
dansanduleac Oct 26, 2018
373a23f
Factor out try_parse_response and is_empty_container
dansanduleac Oct 26, 2018
b672466
make ClientRequest public for testing
dansanduleac Oct 27, 2018
219226f
Fix validation order
dansanduleac Oct 27, 2018
e9652fc
Some tests
dansanduleac Oct 27, 2018
445909f
abstract out with_server_under_test + run_test_case
dansanduleac Oct 27, 2018
70f1bb9
use builders
dansanduleac Oct 27, 2018
9661ed4
test 204 accepted back for 'null' optional value
dansanduleac Oct 27, 2018
1eecbfc
format
dansanduleac Oct 27, 2018
bc4fc92
clarify comment
dansanduleac Oct 27, 2018
781550c
Make ServerUnderTest routes dynamic, yay!
dansanduleac Oct 27, 2018
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 53 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
members = [
"verification-server",
"verification-common",
"verification-client",
"verification-error",
"verification-error-derive",
"verification-http",
Expand Down
41 changes: 41 additions & 0 deletions verification-client/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
[package]
name = "conjure-verification-client"
version = "0.1.0"
authors = ["Felipe Orozco <forozco@palantir.com>", "Dan Sanduleac <dsanduleac@palantir.com>"]
license-file = "../LICENSE"

[dependencies]
conjure-verification-common = { path = "../verification-common" }
conjure-verification-error = { path = "../verification-error" }
conjure-verification-error-derive = { path = "../verification-error-derive" }
conjure-verification-http-client = { path = "../verification-http-client" }
conjure-verification-http = { path = "../verification-http" }
conjure-verification-http-server = { path = "../verification-http-server" }
serde-conjure = { path = "../serde-conjure" }
serde-conjure-derive = { path = "../serde-conjure-derive" }

bytes = "0.4"
derive_more = "0.11"
uuid = { version = "0.6", features = ["v4", "serde"] }
either = "1.5"
futures = "0.1.21"
http = "0.1"
hyper = "0.12"
itertools = "0.7.4"
lazy_static = "1.0"
log = "0.4"
mime = "0.3"
pretty_env_logger = "0.2"
serde = "1.0"
serde-value = "0.5.2"
serde_derive = "1.0"
serde_json = "1.0"
serde_yaml = "0.7"
serde_plain = "0.3"
typed-headers = "0.1"
zipkin = "0.3"

[dev-dependencies]
tokio = "0.1"
url = "1.0"
pretty_assertions = "0.5.1"
101 changes: 101 additions & 0 deletions verification-client/src/errors.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
// (c) Copyright 2018 Palantir Technologies Inc. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

use conjure::value::ConjureValue;
use hyper::StatusCode;
use serde_json;
use std::fmt::Display;
use test_spec::EndpointName;

#[derive(ErrorType)]
#[error_type(namespace = "ConjureVerificationClient")]
pub enum VerificationError {
#[error_type(code = "InvalidArgument")]
InvalidEndpointParameter {
#[error_type(safe)]
endpoint_name: EndpointName,
},
#[error_type(code = "FailedPrecondition")]
UnexpectedBody { body_size: usize },
#[error_type(code = "FailedPrecondition")]
UnexpectedContentType {
#[error_type(safe)]
content_type: String,
},
#[error_type(code = "FailedPrecondition")]
ConfirmationFailure {
#[error_type(safe)]
expected_body_raw: String,
#[error_type(safe)]
expected_body_conjure: String,
#[error_type(safe)]
response_body_raw: String,
#[error_type(safe)]
response_body_conjure: String,
#[error_type(safe)]
cause: String,
},
#[error_type(code = "FailedPrecondition")]
CouldNotParseServerResponse {
#[error_type(safe)]
response_body: String,
#[error_type(safe)]
cause: String,
},
#[error_type(code = "FailedPrecondition")]
ServerUnderTestConnectionError {
#[error_type(safe)]
cause: String,
},
#[error_type(code = "InvalidArgument")]
UnexpectedResponseCode {
#[error_type(safe)]
code: StatusCode,
},
#[error_type(code = "InvalidArgument")]
UrlParseFailure { url: String },
#[error_type(code = "InvalidArgument")]
IndexOutOfBounds {
#[error_type(safe)]
index: usize,
#[error_type(safe)]
max_index: usize,
},
#[error_type(code = "CustomClient")]
ClientIo,
}

impl VerificationError {
pub fn confirmation_failure<E>(
expected_body_str: &str,
expected_body: &ConjureValue,
response_body_str: &serde_json::Value,
// Option because it might be un-parseable as ConjureValue
response_body: Option<&ConjureValue>,
cause: E,
) -> VerificationError
where
E: Display,
{
VerificationError::ConfirmationFailure {
expected_body_conjure: serde_json::ser::to_string(expected_body).unwrap(),
expected_body_raw: expected_body_str.to_string(),
response_body_conjure: response_body
.map(|rp| serde_json::ser::to_string(rp).unwrap())
.unwrap_or_else(|| "<undefined>".to_string()),
response_body_raw: response_body_str.to_string(),
cause: format!("{}", cause),
}
}
}
Loading