mirror of
https://gitlab.com/msrd0/gotham-restful.git
synced 2025-05-09 16:10:42 +00:00
Replace methods with more flexible endpoints
This commit is contained in:
parent
0ac0f0f504
commit
b807ae2796
87 changed files with 1497 additions and 1512 deletions
|
@ -30,55 +30,57 @@ struct FooSearch {
|
|||
}
|
||||
|
||||
const READ_ALL_RESPONSE: &[u8] = b"1ARwwSPVyOKpJKrYwqGgECPVWDl1BqajAAj7g7WJ3e";
|
||||
#[read_all(FooResource)]
|
||||
#[read_all]
|
||||
async fn read_all() -> Raw<&'static [u8]> {
|
||||
Raw::new(READ_ALL_RESPONSE, TEXT_PLAIN)
|
||||
}
|
||||
|
||||
const READ_RESPONSE: &[u8] = b"FEReHoeBKU17X2bBpVAd1iUvktFL43CDu0cFYHdaP9";
|
||||
#[read(FooResource)]
|
||||
#[read]
|
||||
async fn read(_id: u64) -> Raw<&'static [u8]> {
|
||||
Raw::new(READ_RESPONSE, TEXT_PLAIN)
|
||||
}
|
||||
|
||||
const SEARCH_RESPONSE: &[u8] = b"AWqcQUdBRHXKh3at4u79mdupOAfEbnTcx71ogCVF0E";
|
||||
#[search(FooResource)]
|
||||
#[search]
|
||||
async fn search(_body: FooSearch) -> Raw<&'static [u8]> {
|
||||
Raw::new(SEARCH_RESPONSE, TEXT_PLAIN)
|
||||
}
|
||||
|
||||
const CREATE_RESPONSE: &[u8] = b"y6POY7wOMAB0jBRBw0FJT7DOpUNbhmT8KdpQPLkI83";
|
||||
#[create(FooResource)]
|
||||
#[create]
|
||||
async fn create(_body: FooBody) -> Raw<&'static [u8]> {
|
||||
Raw::new(CREATE_RESPONSE, TEXT_PLAIN)
|
||||
}
|
||||
|
||||
const CHANGE_ALL_RESPONSE: &[u8] = b"QlbYg8gHE9OQvvk3yKjXJLTSXlIrg9mcqhfMXJmQkv";
|
||||
#[change_all(FooResource)]
|
||||
#[change_all]
|
||||
async fn change_all(_body: FooBody) -> Raw<&'static [u8]> {
|
||||
Raw::new(CHANGE_ALL_RESPONSE, TEXT_PLAIN)
|
||||
}
|
||||
|
||||
const CHANGE_RESPONSE: &[u8] = b"qGod55RUXkT1lgPO8h0uVM6l368O2S0GrwENZFFuRu";
|
||||
#[change(FooResource)]
|
||||
#[change]
|
||||
async fn change(_id: u64, _body: FooBody) -> Raw<&'static [u8]> {
|
||||
Raw::new(CHANGE_RESPONSE, TEXT_PLAIN)
|
||||
}
|
||||
|
||||
const REMOVE_ALL_RESPONSE: &[u8] = b"Y36kZ749MRk2Nem4BedJABOZiZWPLOtiwLfJlGTwm5";
|
||||
#[remove_all(FooResource)]
|
||||
#[remove_all]
|
||||
async fn remove_all() -> Raw<&'static [u8]> {
|
||||
Raw::new(REMOVE_ALL_RESPONSE, TEXT_PLAIN)
|
||||
}
|
||||
|
||||
const REMOVE_RESPONSE: &[u8] = b"CwRzBrKErsVZ1N7yeNfjZuUn1MacvgBqk4uPOFfDDq";
|
||||
#[remove(FooResource)]
|
||||
#[remove]
|
||||
async fn remove(_id: u64) -> Raw<&'static [u8]> {
|
||||
Raw::new(REMOVE_RESPONSE, TEXT_PLAIN)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn async_methods() {
|
||||
let _ = pretty_env_logger::try_init_timed();
|
||||
|
||||
let server = TestServer::new(build_simple_router(|router| {
|
||||
router.resource::<FooResource>("foo");
|
||||
}))
|
||||
|
|
|
@ -16,10 +16,10 @@ use mime::TEXT_PLAIN;
|
|||
#[resource(read_all, change_all)]
|
||||
struct FooResource;
|
||||
|
||||
#[read_all(FooResource)]
|
||||
#[read_all]
|
||||
fn read_all() {}
|
||||
|
||||
#[change_all(FooResource)]
|
||||
#[change_all]
|
||||
fn change_all(_body: Raw<Vec<u8>>) {}
|
||||
|
||||
fn test_server(cfg: CorsConfig) -> TestServer {
|
||||
|
|
|
@ -15,7 +15,7 @@ struct Foo {
|
|||
content_type: Mime
|
||||
}
|
||||
|
||||
#[create(FooResource)]
|
||||
#[create]
|
||||
fn create(body: Foo) -> Raw<Vec<u8>> {
|
||||
Raw::new(body.content, body.content_type)
|
||||
}
|
||||
|
|
|
@ -22,23 +22,23 @@ use util::{test_get_response, test_openapi_response};
|
|||
const IMAGE_RESPONSE : &[u8] = b"iVBORw0KGgoAAAANSUhEUgAAAAEAAAABAQMAAAAl21bKAAAAA1BMVEUA/wA0XsCoAAAAAXRSTlN/gFy0ywAAAApJREFUeJxjYgAAAAYAAzY3fKgAAAAASUVORK5CYII=";
|
||||
|
||||
#[derive(Resource)]
|
||||
#[resource(read, change)]
|
||||
#[resource(get_image, set_image)]
|
||||
struct ImageResource;
|
||||
|
||||
#[derive(FromBody, RequestBody)]
|
||||
#[supported_types(IMAGE_PNG)]
|
||||
struct Image(Vec<u8>);
|
||||
|
||||
#[read(ImageResource, operation_id = "getImage")]
|
||||
#[read(operation_id = "getImage")]
|
||||
fn get_image(_id: u64) -> Raw<&'static [u8]> {
|
||||
Raw::new(IMAGE_RESPONSE, "image/png;base64".parse().unwrap())
|
||||
}
|
||||
|
||||
#[change(ImageResource, operation_id = "setImage")]
|
||||
#[change(operation_id = "setImage")]
|
||||
fn set_image(_id: u64, _image: Image) {}
|
||||
|
||||
#[derive(Resource)]
|
||||
#[resource(read, search)]
|
||||
#[resource(read_secret, search_secret)]
|
||||
struct SecretResource;
|
||||
|
||||
#[derive(Deserialize, Clone)]
|
||||
|
@ -67,13 +67,13 @@ struct SecretQuery {
|
|||
minute: Option<u16>
|
||||
}
|
||||
|
||||
#[read(SecretResource)]
|
||||
#[read]
|
||||
fn read_secret(auth: AuthStatus, _id: NaiveDateTime) -> AuthSuccess<Secret> {
|
||||
auth.ok()?;
|
||||
Ok(Secret { code: 4.2 })
|
||||
}
|
||||
|
||||
#[search(SecretResource)]
|
||||
#[search]
|
||||
fn search_secret(auth: AuthStatus, _query: SecretQuery) -> AuthSuccess<Secrets> {
|
||||
auth.ok()?;
|
||||
Ok(Secrets {
|
||||
|
@ -82,7 +82,7 @@ fn search_secret(auth: AuthStatus, _query: SecretQuery) -> AuthSuccess<Secrets>
|
|||
}
|
||||
|
||||
#[test]
|
||||
fn openapi_supports_scope() {
|
||||
fn openapi_specification() {
|
||||
let info = OpenapiInfo {
|
||||
title: "This is just a test".to_owned(),
|
||||
version: "1.2.3".to_owned(),
|
||||
|
|
|
@ -15,7 +15,7 @@ const RESPONSE: &[u8] = b"This is the only valid response.";
|
|||
#[resource(read_all)]
|
||||
struct FooResource;
|
||||
|
||||
#[read_all(FooResource)]
|
||||
#[read_all]
|
||||
fn read_all() -> Raw<&'static [u8]> {
|
||||
Raw::new(RESPONSE, TEXT_PLAIN)
|
||||
}
|
||||
|
|
|
@ -30,55 +30,57 @@ struct FooSearch {
|
|||
}
|
||||
|
||||
const READ_ALL_RESPONSE: &[u8] = b"1ARwwSPVyOKpJKrYwqGgECPVWDl1BqajAAj7g7WJ3e";
|
||||
#[read_all(FooResource)]
|
||||
#[read_all]
|
||||
fn read_all() -> Raw<&'static [u8]> {
|
||||
Raw::new(READ_ALL_RESPONSE, TEXT_PLAIN)
|
||||
}
|
||||
|
||||
const READ_RESPONSE: &[u8] = b"FEReHoeBKU17X2bBpVAd1iUvktFL43CDu0cFYHdaP9";
|
||||
#[read(FooResource)]
|
||||
#[read]
|
||||
fn read(_id: u64) -> Raw<&'static [u8]> {
|
||||
Raw::new(READ_RESPONSE, TEXT_PLAIN)
|
||||
}
|
||||
|
||||
const SEARCH_RESPONSE: &[u8] = b"AWqcQUdBRHXKh3at4u79mdupOAfEbnTcx71ogCVF0E";
|
||||
#[search(FooResource)]
|
||||
#[search]
|
||||
fn search(_body: FooSearch) -> Raw<&'static [u8]> {
|
||||
Raw::new(SEARCH_RESPONSE, TEXT_PLAIN)
|
||||
}
|
||||
|
||||
const CREATE_RESPONSE: &[u8] = b"y6POY7wOMAB0jBRBw0FJT7DOpUNbhmT8KdpQPLkI83";
|
||||
#[create(FooResource)]
|
||||
#[create]
|
||||
fn create(_body: FooBody) -> Raw<&'static [u8]> {
|
||||
Raw::new(CREATE_RESPONSE, TEXT_PLAIN)
|
||||
}
|
||||
|
||||
const CHANGE_ALL_RESPONSE: &[u8] = b"QlbYg8gHE9OQvvk3yKjXJLTSXlIrg9mcqhfMXJmQkv";
|
||||
#[change_all(FooResource)]
|
||||
#[change_all]
|
||||
fn change_all(_body: FooBody) -> Raw<&'static [u8]> {
|
||||
Raw::new(CHANGE_ALL_RESPONSE, TEXT_PLAIN)
|
||||
}
|
||||
|
||||
const CHANGE_RESPONSE: &[u8] = b"qGod55RUXkT1lgPO8h0uVM6l368O2S0GrwENZFFuRu";
|
||||
#[change(FooResource)]
|
||||
#[change]
|
||||
fn change(_id: u64, _body: FooBody) -> Raw<&'static [u8]> {
|
||||
Raw::new(CHANGE_RESPONSE, TEXT_PLAIN)
|
||||
}
|
||||
|
||||
const REMOVE_ALL_RESPONSE: &[u8] = b"Y36kZ749MRk2Nem4BedJABOZiZWPLOtiwLfJlGTwm5";
|
||||
#[remove_all(FooResource)]
|
||||
#[remove_all]
|
||||
fn remove_all() -> Raw<&'static [u8]> {
|
||||
Raw::new(REMOVE_ALL_RESPONSE, TEXT_PLAIN)
|
||||
}
|
||||
|
||||
const REMOVE_RESPONSE: &[u8] = b"CwRzBrKErsVZ1N7yeNfjZuUn1MacvgBqk4uPOFfDDq";
|
||||
#[remove(FooResource)]
|
||||
#[remove]
|
||||
fn remove(_id: u64) -> Raw<&'static [u8]> {
|
||||
Raw::new(REMOVE_RESPONSE, TEXT_PLAIN)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn sync_methods() {
|
||||
let _ = pretty_env_logger::try_init_timed();
|
||||
|
||||
let server = TestServer::new(build_simple_router(|router| {
|
||||
router.resource::<FooResource>("foo");
|
||||
}))
|
||||
|
|
|
@ -6,23 +6,12 @@ fn trybuild_ui() {
|
|||
let t = TestCases::new();
|
||||
|
||||
// always enabled
|
||||
t.compile_fail("tests/ui/from_body_enum.rs");
|
||||
t.compile_fail("tests/ui/method_async_state.rs");
|
||||
t.compile_fail("tests/ui/method_for_unknown_resource.rs");
|
||||
t.compile_fail("tests/ui/method_no_resource.rs");
|
||||
t.compile_fail("tests/ui/method_self.rs");
|
||||
t.compile_fail("tests/ui/method_too_few_args.rs");
|
||||
t.compile_fail("tests/ui/method_too_many_args.rs");
|
||||
t.compile_fail("tests/ui/method_unsafe.rs");
|
||||
t.compile_fail("tests/ui/resource_unknown_method.rs");
|
||||
t.compile_fail("tests/ui/endpoint/*.rs");
|
||||
t.compile_fail("tests/ui/from_body/*.rs");
|
||||
t.compile_fail("tests/ui/resource/*.rs");
|
||||
|
||||
// require the openapi feature
|
||||
if cfg!(feature = "openapi") {
|
||||
t.compile_fail("tests/ui/openapi_type_enum_with_fields.rs");
|
||||
t.compile_fail("tests/ui/openapi_type_nullable_non_bool.rs");
|
||||
t.compile_fail("tests/ui/openapi_type_rename_non_string.rs");
|
||||
t.compile_fail("tests/ui/openapi_type_tuple_struct.rs");
|
||||
t.compile_fail("tests/ui/openapi_type_union.rs");
|
||||
t.compile_fail("tests/ui/openapi_type_unknown_key.rs");
|
||||
t.compile_fail("tests/ui/openapi_type/*.rs");
|
||||
}
|
||||
}
|
||||
|
|
12
tests/ui/endpoint/async_state.rs
Normal file
12
tests/ui/endpoint/async_state.rs
Normal file
|
@ -0,0 +1,12 @@
|
|||
#[macro_use]
|
||||
extern crate gotham_restful;
|
||||
use gotham_restful::State;
|
||||
|
||||
#[derive(Resource)]
|
||||
#[resource(read_all)]
|
||||
struct FooResource;
|
||||
|
||||
#[read_all]
|
||||
async fn read_all(state: &State) {}
|
||||
|
||||
fn main() {}
|
5
tests/ui/endpoint/async_state.stderr
Normal file
5
tests/ui/endpoint/async_state.stderr
Normal file
|
@ -0,0 +1,5 @@
|
|||
error: Endpoint handler functions that are async must not take `&State` as an argument, consider taking `&mut State`
|
||||
--> $DIR/async_state.rs:10:19
|
||||
|
|
||||
10 | async fn read_all(state: &State) {}
|
||||
| ^^^^^
|
|
@ -1,14 +1,11 @@
|
|||
#[macro_use] extern crate gotham_restful;
|
||||
#[macro_use]
|
||||
extern crate gotham_restful;
|
||||
|
||||
#[derive(Resource)]
|
||||
#[resource(read_all)]
|
||||
struct FooResource;
|
||||
|
||||
#[read_all(FooResource)]
|
||||
fn read_all(self)
|
||||
{
|
||||
}
|
||||
fn read_all() {}
|
||||
|
||||
fn main()
|
||||
{
|
||||
}
|
||||
fn main() {}
|
11
tests/ui/endpoint/invalid_attribute.stderr
Normal file
11
tests/ui/endpoint/invalid_attribute.stderr
Normal file
|
@ -0,0 +1,11 @@
|
|||
error: Invalid attribute syntax
|
||||
--> $DIR/invalid_attribute.rs:8:12
|
||||
|
|
||||
8 | #[read_all(FooResource)]
|
||||
| ^^^^^^^^^^^
|
||||
|
||||
error[E0412]: cannot find type `read_all___gotham_restful_endpoint` in this scope
|
||||
--> $DIR/invalid_attribute.rs:5:12
|
||||
|
|
||||
5 | #[resource(read_all)]
|
||||
| ^^^^^^^^ not found in this scope
|
|
@ -1,14 +1,11 @@
|
|||
#[macro_use] extern crate gotham_restful;
|
||||
#[macro_use]
|
||||
extern crate gotham_restful;
|
||||
|
||||
#[derive(Resource)]
|
||||
#[resource(read_all)]
|
||||
struct FooResource;
|
||||
|
||||
#[read_all]
|
||||
fn read_all()
|
||||
{
|
||||
}
|
||||
fn read_all(self) {}
|
||||
|
||||
fn main()
|
||||
{
|
||||
}
|
||||
fn main() {}
|
19
tests/ui/endpoint/self.stderr
Normal file
19
tests/ui/endpoint/self.stderr
Normal file
|
@ -0,0 +1,19 @@
|
|||
error: Didn't expect self parameter
|
||||
--> $DIR/self.rs:9:13
|
||||
|
|
||||
9 | fn read_all(self) {}
|
||||
| ^^^^
|
||||
|
||||
error: `self` parameter is only allowed in associated functions
|
||||
--> $DIR/self.rs:9:13
|
||||
|
|
||||
9 | fn read_all(self) {}
|
||||
| ^^^^ not semantically valid as function parameter
|
||||
|
|
||||
= note: associated functions are those in `impl` or `trait` definitions
|
||||
|
||||
error[E0412]: cannot find type `read_all___gotham_restful_endpoint` in this scope
|
||||
--> $DIR/self.rs:5:12
|
||||
|
|
||||
5 | #[resource(read_all)]
|
||||
| ^^^^^^^^ not found in this scope
|
11
tests/ui/endpoint/too_few_args.rs
Normal file
11
tests/ui/endpoint/too_few_args.rs
Normal file
|
@ -0,0 +1,11 @@
|
|||
#[macro_use]
|
||||
extern crate gotham_restful;
|
||||
|
||||
#[derive(Resource)]
|
||||
#[resource(read)]
|
||||
struct FooResource;
|
||||
|
||||
#[read]
|
||||
fn read() {}
|
||||
|
||||
fn main() {}
|
11
tests/ui/endpoint/too_few_args.stderr
Normal file
11
tests/ui/endpoint/too_few_args.stderr
Normal file
|
@ -0,0 +1,11 @@
|
|||
error: Too few arguments
|
||||
--> $DIR/too_few_args.rs:9:4
|
||||
|
|
||||
9 | fn read() {}
|
||||
| ^^^^
|
||||
|
||||
error[E0412]: cannot find type `read___gotham_restful_endpoint` in this scope
|
||||
--> $DIR/too_few_args.rs:5:12
|
||||
|
|
||||
5 | #[resource(read)]
|
||||
| ^^^^ not found in this scope
|
11
tests/ui/endpoint/too_many_args.rs
Normal file
11
tests/ui/endpoint/too_many_args.rs
Normal file
|
@ -0,0 +1,11 @@
|
|||
#[macro_use]
|
||||
extern crate gotham_restful;
|
||||
|
||||
#[derive(Resource)]
|
||||
#[resource(read_all)]
|
||||
struct FooResource;
|
||||
|
||||
#[read_all]
|
||||
fn read_all(_id: u64) {}
|
||||
|
||||
fn main() {}
|
11
tests/ui/endpoint/too_many_args.stderr
Normal file
11
tests/ui/endpoint/too_many_args.stderr
Normal file
|
@ -0,0 +1,11 @@
|
|||
error: Too many arguments
|
||||
--> $DIR/too_many_args.rs:9:4
|
||||
|
|
||||
9 | fn read_all(_id: u64) {}
|
||||
| ^^^^^^^^
|
||||
|
||||
error[E0412]: cannot find type `read_all___gotham_restful_endpoint` in this scope
|
||||
--> $DIR/too_many_args.rs:5:12
|
||||
|
|
||||
5 | #[resource(read_all)]
|
||||
| ^^^^^^^^ not found in this scope
|
11
tests/ui/endpoint/unknown_attribute.rs
Normal file
11
tests/ui/endpoint/unknown_attribute.rs
Normal file
|
@ -0,0 +1,11 @@
|
|||
#[macro_use]
|
||||
extern crate gotham_restful;
|
||||
|
||||
#[derive(Resource)]
|
||||
#[resource(read_all)]
|
||||
struct FooResource;
|
||||
|
||||
#[read_all(pineapple = "on pizza")]
|
||||
fn read_all() {}
|
||||
|
||||
fn main() {}
|
11
tests/ui/endpoint/unknown_attribute.stderr
Normal file
11
tests/ui/endpoint/unknown_attribute.stderr
Normal file
|
@ -0,0 +1,11 @@
|
|||
error: Unknown attribute
|
||||
--> $DIR/unknown_attribute.rs:8:12
|
||||
|
|
||||
8 | #[read_all(pineapple = "on pizza")]
|
||||
| ^^^^^^^^^
|
||||
|
||||
error[E0412]: cannot find type `read_all___gotham_restful_endpoint` in this scope
|
||||
--> $DIR/unknown_attribute.rs:5:12
|
||||
|
|
||||
5 | #[resource(read_all)]
|
||||
| ^^^^^^^^ not found in this scope
|
11
tests/ui/endpoint/unsafe.rs
Normal file
11
tests/ui/endpoint/unsafe.rs
Normal file
|
@ -0,0 +1,11 @@
|
|||
#[macro_use]
|
||||
extern crate gotham_restful;
|
||||
|
||||
#[derive(Resource)]
|
||||
#[resource(read_all)]
|
||||
struct FooResource;
|
||||
|
||||
#[read_all]
|
||||
unsafe fn read_all() {}
|
||||
|
||||
fn main() {}
|
11
tests/ui/endpoint/unsafe.stderr
Normal file
11
tests/ui/endpoint/unsafe.stderr
Normal file
|
@ -0,0 +1,11 @@
|
|||
error: Endpoint handler methods must not be unsafe
|
||||
--> $DIR/unsafe.rs:9:1
|
||||
|
|
||||
9 | unsafe fn read_all() {}
|
||||
| ^^^^^^
|
||||
|
||||
error[E0412]: cannot find type `read_all___gotham_restful_endpoint` in this scope
|
||||
--> $DIR/unsafe.rs:5:12
|
||||
|
|
||||
5 | #[resource(read_all)]
|
||||
| ^^^^^^^^ not found in this scope
|
10
tests/ui/from_body/enum.rs
Normal file
10
tests/ui/from_body/enum.rs
Normal file
|
@ -0,0 +1,10 @@
|
|||
#[macro_use]
|
||||
extern crate gotham_restful;
|
||||
|
||||
#[derive(FromBody)]
|
||||
enum FromBodyEnum {
|
||||
SomeVariant(Vec<u8>),
|
||||
OtherVariant(String)
|
||||
}
|
||||
|
||||
fn main() {}
|
|
@ -1,5 +1,5 @@
|
|||
error: #[derive(FromBody)] only works for structs
|
||||
--> $DIR/from_body_enum.rs:4:1
|
||||
--> $DIR/enum.rs:5:1
|
||||
|
|
||||
4 | enum FromBodyEnum
|
||||
5 | enum FromBodyEnum {
|
||||
| ^^^^
|
|
@ -1,12 +0,0 @@
|
|||
#[macro_use] extern crate gotham_restful;
|
||||
|
||||
#[derive(FromBody)]
|
||||
enum FromBodyEnum
|
||||
{
|
||||
SomeVariant(Vec<u8>),
|
||||
OtherVariant(String)
|
||||
}
|
||||
|
||||
fn main()
|
||||
{
|
||||
}
|
|
@ -1,15 +0,0 @@
|
|||
#[macro_use] extern crate gotham_restful;
|
||||
use gotham_restful::State;
|
||||
|
||||
#[derive(Resource)]
|
||||
#[resource(read_all)]
|
||||
struct FooResource;
|
||||
|
||||
#[read_all(FooResource)]
|
||||
async fn read_all(state : &State)
|
||||
{
|
||||
}
|
||||
|
||||
fn main()
|
||||
{
|
||||
}
|
|
@ -1,5 +0,0 @@
|
|||
error: async fn must not take &State as an argument as State is not Sync, consider taking &mut State
|
||||
--> $DIR/method_async_state.rs:9:19
|
||||
|
|
||||
9 | async fn read_all(state : &State)
|
||||
| ^^^^^
|
|
@ -1,10 +0,0 @@
|
|||
#[macro_use] extern crate gotham_restful;
|
||||
|
||||
#[read_all(UnknownResource)]
|
||||
fn read_all()
|
||||
{
|
||||
}
|
||||
|
||||
fn main()
|
||||
{
|
||||
}
|
|
@ -1,5 +0,0 @@
|
|||
error[E0412]: cannot find type `UnknownResource` in this scope
|
||||
--> $DIR/method_for_unknown_resource.rs:3:12
|
||||
|
|
||||
3 | #[read_all(UnknownResource)]
|
||||
| ^^^^^^^^^^^^^^^ not found in this scope
|
|
@ -1,15 +0,0 @@
|
|||
error: Missing Resource struct. Example: #[read_all(MyResource)]
|
||||
--> $DIR/method_no_resource.rs:7:1
|
||||
|
|
||||
7 | #[read_all]
|
||||
| ^^^^^^^^^^^
|
||||
|
|
||||
= note: this error originates in an attribute macro (in Nightly builds, run with -Z macro-backtrace for more info)
|
||||
|
||||
error[E0425]: cannot find function `_gotham_restful_foo_resource_read_all_setup_impl` in this scope
|
||||
--> $DIR/method_no_resource.rs:3:10
|
||||
|
|
||||
3 | #[derive(Resource)]
|
||||
| ^^^^^^^^ not found in this scope
|
||||
|
|
||||
= note: this error originates in a derive macro (in Nightly builds, run with -Z macro-backtrace for more info)
|
|
@ -1,13 +0,0 @@
|
|||
error: Didn't expect self parameter
|
||||
--> $DIR/method_self.rs:8:13
|
||||
|
|
||||
8 | fn read_all(self)
|
||||
| ^^^^
|
||||
|
||||
error: `self` parameter is only allowed in associated functions
|
||||
--> $DIR/method_self.rs:8:13
|
||||
|
|
||||
8 | fn read_all(self)
|
||||
| ^^^^ not semantically valid as function parameter
|
||||
|
|
||||
= note: associated functions are those in `impl` or `trait` definitions
|
|
@ -1,14 +0,0 @@
|
|||
#[macro_use] extern crate gotham_restful;
|
||||
|
||||
#[derive(Resource)]
|
||||
#[resource(read)]
|
||||
struct FooResource;
|
||||
|
||||
#[read(FooResource)]
|
||||
fn read()
|
||||
{
|
||||
}
|
||||
|
||||
fn main()
|
||||
{
|
||||
}
|
|
@ -1,5 +0,0 @@
|
|||
error: Too few arguments
|
||||
--> $DIR/method_too_few_args.rs:8:4
|
||||
|
|
||||
8 | fn read()
|
||||
| ^^^^
|
|
@ -1,14 +0,0 @@
|
|||
#[macro_use] extern crate gotham_restful;
|
||||
|
||||
#[derive(Resource)]
|
||||
#[resource(read_all)]
|
||||
struct FooResource;
|
||||
|
||||
#[read_all(FooResource)]
|
||||
fn read_all(_id : u64)
|
||||
{
|
||||
}
|
||||
|
||||
fn main()
|
||||
{
|
||||
}
|
|
@ -1,5 +0,0 @@
|
|||
error: Too many arguments
|
||||
--> $DIR/method_too_many_args.rs:8:13
|
||||
|
|
||||
8 | fn read_all(_id : u64)
|
||||
| ^^^
|
|
@ -1,14 +0,0 @@
|
|||
#[macro_use] extern crate gotham_restful;
|
||||
|
||||
#[derive(Resource)]
|
||||
#[resource(read_all)]
|
||||
struct FooResource;
|
||||
|
||||
#[read_all(FooResource)]
|
||||
unsafe fn read_all()
|
||||
{
|
||||
}
|
||||
|
||||
fn main()
|
||||
{
|
||||
}
|
|
@ -1,5 +0,0 @@
|
|||
error: Resource methods must not be unsafe
|
||||
--> $DIR/method_unsafe.rs:8:1
|
||||
|
|
||||
8 | unsafe fn read_all()
|
||||
| ^^^^^^
|
12
tests/ui/openapi_type/enum_with_fields.rs
Normal file
12
tests/ui/openapi_type/enum_with_fields.rs
Normal file
|
@ -0,0 +1,12 @@
|
|||
#[macro_use]
|
||||
extern crate gotham_restful;
|
||||
|
||||
#[derive(OpenapiType)]
|
||||
enum Food {
|
||||
Pasta,
|
||||
Pizza { pineapple: bool },
|
||||
Rice,
|
||||
Other(String)
|
||||
}
|
||||
|
||||
fn main() {}
|
|
@ -1,11 +1,11 @@
|
|||
error: #[derive(OpenapiType)] does not support enum variants with fields
|
||||
--> $DIR/openapi_type_enum_with_fields.rs:7:2
|
||||
--> $DIR/enum_with_fields.rs:7:2
|
||||
|
|
||||
7 | Pizza { pineapple : bool },
|
||||
7 | Pizza { pineapple: bool },
|
||||
| ^^^^^
|
||||
|
||||
error: #[derive(OpenapiType)] does not support enum variants with fields
|
||||
--> $DIR/openapi_type_enum_with_fields.rs:9:2
|
||||
--> $DIR/enum_with_fields.rs:9:2
|
||||
|
|
||||
9 | Other(String)
|
||||
| ^^^^^
|
10
tests/ui/openapi_type/nullable_non_bool.rs
Normal file
10
tests/ui/openapi_type/nullable_non_bool.rs
Normal file
|
@ -0,0 +1,10 @@
|
|||
#[macro_use]
|
||||
extern crate gotham_restful;
|
||||
|
||||
#[derive(OpenapiType)]
|
||||
struct Foo {
|
||||
#[openapi(nullable = "yes, please")]
|
||||
bar: String
|
||||
}
|
||||
|
||||
fn main() {}
|
|
@ -1,5 +1,5 @@
|
|||
error: Expected bool
|
||||
--> $DIR/openapi_type_nullable_non_bool.rs:6:23
|
||||
--> $DIR/nullable_non_bool.rs:6:23
|
||||
|
|
||||
6 | #[openapi(nullable = "yes, please")]
|
||||
| ^^^^^^^^^^^^^
|
10
tests/ui/openapi_type/rename_non_string.rs
Normal file
10
tests/ui/openapi_type/rename_non_string.rs
Normal file
|
@ -0,0 +1,10 @@
|
|||
#[macro_use]
|
||||
extern crate gotham_restful;
|
||||
|
||||
#[derive(OpenapiType)]
|
||||
struct Foo {
|
||||
#[openapi(rename = 42)]
|
||||
bar: String
|
||||
}
|
||||
|
||||
fn main() {}
|
|
@ -1,5 +1,5 @@
|
|||
error: Expected string literal
|
||||
--> $DIR/openapi_type_rename_non_string.rs:6:21
|
||||
--> $DIR/rename_non_string.rs:6:21
|
||||
|
|
||||
6 | #[openapi(rename = 42)]
|
||||
| ^^
|
7
tests/ui/openapi_type/tuple_struct.rs
Normal file
7
tests/ui/openapi_type/tuple_struct.rs
Normal file
|
@ -0,0 +1,7 @@
|
|||
#[macro_use]
|
||||
extern crate gotham_restful;
|
||||
|
||||
#[derive(OpenapiType)]
|
||||
struct Foo(String);
|
||||
|
||||
fn main() {}
|
|
@ -1,5 +1,5 @@
|
|||
error: #[derive(OpenapiType)] does not support unnamed fields
|
||||
--> $DIR/openapi_type_tuple_struct.rs:4:11
|
||||
--> $DIR/tuple_struct.rs:5:11
|
||||
|
|
||||
4 | struct Foo(String);
|
||||
5 | struct Foo(String);
|
||||
| ^^^^^^^^
|
10
tests/ui/openapi_type/union.rs
Normal file
10
tests/ui/openapi_type/union.rs
Normal file
|
@ -0,0 +1,10 @@
|
|||
#[macro_use]
|
||||
extern crate gotham_restful;
|
||||
|
||||
#[derive(OpenapiType)]
|
||||
union IntOrPointer {
|
||||
int: u64,
|
||||
pointer: *mut String
|
||||
}
|
||||
|
||||
fn main() {}
|
|
@ -1,5 +1,5 @@
|
|||
error: #[derive(OpenapiType)] only works for structs and enums
|
||||
--> $DIR/openapi_type_union.rs:4:1
|
||||
--> $DIR/union.rs:5:1
|
||||
|
|
||||
4 | union IntOrPointer
|
||||
5 | union IntOrPointer {
|
||||
| ^^^^^
|
10
tests/ui/openapi_type/unknown_key.rs
Normal file
10
tests/ui/openapi_type/unknown_key.rs
Normal file
|
@ -0,0 +1,10 @@
|
|||
#[macro_use]
|
||||
extern crate gotham_restful;
|
||||
|
||||
#[derive(OpenapiType)]
|
||||
struct Foo {
|
||||
#[openapi(like = "pizza")]
|
||||
bar: String
|
||||
}
|
||||
|
||||
fn main() {}
|
|
@ -1,5 +1,5 @@
|
|||
error: Unknown key
|
||||
--> $DIR/openapi_type_unknown_key.rs:6:12
|
||||
--> $DIR/unknown_key.rs:6:12
|
||||
|
|
||||
6 | #[openapi(like = "pizza")]
|
||||
| ^^^^
|
|
@ -1,14 +0,0 @@
|
|||
#[macro_use] extern crate gotham_restful;
|
||||
|
||||
#[derive(OpenapiType)]
|
||||
enum Food
|
||||
{
|
||||
Pasta,
|
||||
Pizza { pineapple : bool },
|
||||
Rice,
|
||||
Other(String)
|
||||
}
|
||||
|
||||
fn main()
|
||||
{
|
||||
}
|
|
@ -1,12 +0,0 @@
|
|||
#[macro_use] extern crate gotham_restful;
|
||||
|
||||
#[derive(OpenapiType)]
|
||||
struct Foo
|
||||
{
|
||||
#[openapi(nullable = "yes, please")]
|
||||
bar : String
|
||||
}
|
||||
|
||||
fn main()
|
||||
{
|
||||
}
|
|
@ -1,12 +0,0 @@
|
|||
#[macro_use] extern crate gotham_restful;
|
||||
|
||||
#[derive(OpenapiType)]
|
||||
struct Foo
|
||||
{
|
||||
#[openapi(rename = 42)]
|
||||
bar : String
|
||||
}
|
||||
|
||||
fn main()
|
||||
{
|
||||
}
|
|
@ -1,8 +0,0 @@
|
|||
#[macro_use] extern crate gotham_restful;
|
||||
|
||||
#[derive(OpenapiType)]
|
||||
struct Foo(String);
|
||||
|
||||
fn main()
|
||||
{
|
||||
}
|
|
@ -1,12 +0,0 @@
|
|||
#[macro_use] extern crate gotham_restful;
|
||||
|
||||
#[derive(OpenapiType)]
|
||||
union IntOrPointer
|
||||
{
|
||||
int: u64,
|
||||
pointer: *mut String
|
||||
}
|
||||
|
||||
fn main()
|
||||
{
|
||||
}
|
|
@ -1,12 +0,0 @@
|
|||
#[macro_use] extern crate gotham_restful;
|
||||
|
||||
#[derive(OpenapiType)]
|
||||
struct Foo
|
||||
{
|
||||
#[openapi(like = "pizza")]
|
||||
bar : String
|
||||
}
|
||||
|
||||
fn main()
|
||||
{
|
||||
}
|
11
tests/ui/resource/unknown_method.rs
Normal file
11
tests/ui/resource/unknown_method.rs
Normal file
|
@ -0,0 +1,11 @@
|
|||
#[macro_use]
|
||||
extern crate gotham_restful;
|
||||
|
||||
#[derive(Resource)]
|
||||
#[resource(read_any)]
|
||||
struct FooResource;
|
||||
|
||||
#[read_all]
|
||||
fn read_all() {}
|
||||
|
||||
fn main() {}
|
8
tests/ui/resource/unknown_method.stderr
Normal file
8
tests/ui/resource/unknown_method.stderr
Normal file
|
@ -0,0 +1,8 @@
|
|||
error[E0412]: cannot find type `read_any___gotham_restful_endpoint` in this scope
|
||||
--> $DIR/unknown_method.rs:5:12
|
||||
|
|
||||
5 | #[resource(read_any)]
|
||||
| ^^^^^^^^ help: a struct with a similar name exists: `read_all___gotham_restful_endpoint`
|
||||
...
|
||||
8 | #[read_all]
|
||||
| ----------- similarly named struct `read_all___gotham_restful_endpoint` defined here
|
|
@ -1,14 +0,0 @@
|
|||
#[macro_use] extern crate gotham_restful;
|
||||
|
||||
#[derive(Resource)]
|
||||
#[resource(read_any)]
|
||||
struct FooResource;
|
||||
|
||||
#[read_all(FooResource)]
|
||||
fn read_all()
|
||||
{
|
||||
}
|
||||
|
||||
fn main()
|
||||
{
|
||||
}
|
|
@ -1,14 +0,0 @@
|
|||
error: Unknown method: `read_any'
|
||||
--> $DIR/resource_unknown_method.rs:4:12
|
||||
|
|
||||
4 | #[resource(read_any)]
|
||||
| ^^^^^^^^
|
||||
|
||||
error[E0277]: the trait bound `FooResource: Resource` is not satisfied
|
||||
--> $DIR/resource_unknown_method.rs:7:1
|
||||
|
|
||||
7 | #[read_all(FooResource)]
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^ the trait `Resource` is not implemented for `FooResource`
|
||||
|
|
||||
= help: see issue #48214
|
||||
= note: this error originates in an attribute macro (in Nightly builds, run with -Z macro-backtrace for more info)
|
15
tests/ui/rustfmt.sh
Executable file
15
tests/ui/rustfmt.sh
Executable file
|
@ -0,0 +1,15 @@
|
|||
#!/bin/bash
|
||||
set -euo pipefail
|
||||
|
||||
rustfmt=${RUSTFMT:-rustfmt}
|
||||
version="$($rustfmt -V)"
|
||||
if [[ $version != *nightly* ]]; then
|
||||
rustfmt="$rustfmt +nightly"
|
||||
fi
|
||||
|
||||
return=0
|
||||
find "$(dirname "$0")" -name '*.rs' -type f | while read file; do
|
||||
$rustfmt --config-path "$(dirname "$0")/../../rustfmt.toml" "$@" "$file" || return=1
|
||||
done
|
||||
|
||||
exit $return
|
|
@ -2,12 +2,14 @@ use gotham::{
|
|||
hyper::Body,
|
||||
test::TestServer
|
||||
};
|
||||
use log::info;
|
||||
use mime::Mime;
|
||||
#[allow(unused_imports)]
|
||||
use std::{fs::File, io::{Read, Write}, str};
|
||||
|
||||
pub fn test_get_response(server : &TestServer, path : &str, expected : &[u8])
|
||||
{
|
||||
info!("GET {}", path);
|
||||
let res = server.client().get(path).perform().unwrap().read_body().unwrap();
|
||||
let body : &[u8] = res.as_ref();
|
||||
assert_eq!(body, expected);
|
||||
|
@ -17,6 +19,7 @@ pub fn test_post_response<B>(server : &TestServer, path : &str, body : B, mime :
|
|||
where
|
||||
B : Into<Body>
|
||||
{
|
||||
info!("POST {}", path);
|
||||
let res = server.client().post(path, body, mime).perform().unwrap().read_body().unwrap();
|
||||
let body : &[u8] = res.as_ref();
|
||||
assert_eq!(body, expected);
|
||||
|
@ -26,6 +29,7 @@ pub fn test_put_response<B>(server : &TestServer, path : &str, body : B, mime :
|
|||
where
|
||||
B : Into<Body>
|
||||
{
|
||||
info!("PUT {}", path);
|
||||
let res = server.client().put(path, body, mime).perform().unwrap().read_body().unwrap();
|
||||
let body : &[u8] = res.as_ref();
|
||||
assert_eq!(body, expected);
|
||||
|
@ -33,6 +37,7 @@ where
|
|||
|
||||
pub fn test_delete_response(server : &TestServer, path : &str, expected : &[u8])
|
||||
{
|
||||
info!("DELETE {}", path);
|
||||
let res = server.client().delete(path).perform().unwrap().read_body().unwrap();
|
||||
let body : &[u8] = res.as_ref();
|
||||
assert_eq!(body, expected);
|
||||
|
@ -41,12 +46,14 @@ pub fn test_delete_response(server : &TestServer, path : &str, expected : &[u8])
|
|||
#[cfg(feature = "openapi")]
|
||||
pub fn test_openapi_response(server : &TestServer, path : &str, output_file : &str)
|
||||
{
|
||||
info!("GET {}", path);
|
||||
let res = server.client().get(path).perform().unwrap().read_body().unwrap();
|
||||
let body = serde_json::to_string_pretty(&serde_json::from_slice::<serde_json::Value>(res.as_ref()).unwrap()).unwrap();
|
||||
match File::open(output_file) {
|
||||
Ok(mut file) => {
|
||||
let mut expected = String::new();
|
||||
file.read_to_string(&mut expected).unwrap();
|
||||
eprintln!("{}", body);
|
||||
assert_eq!(body, expected);
|
||||
},
|
||||
Err(_) => {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue