1 // Copyright (c) 2023 Huawei Device Co., Ltd.
2 // Licensed under the Apache License, Version 2.0 (the "License");
3 // you may not use this file except in compliance with the License.
4 // You may obtain a copy of the License at
5 //
6 // http://www.apache.org/licenses/LICENSE-2.0
7 //
8 // Unless required by applicable law or agreed to in writing, software
9 // distributed under the License is distributed on an "AS IS" BASIS,
10 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11 // See the License for the specific language governing permissions and
12 // limitations under the License.
13
14 #![cfg(all(feature = "sync", feature = "http1_1", feature = "tokio_base"))]
15
16 #[macro_use]
17 mod common;
18
19 use std::sync::Arc;
20
21 use ylong_http_client::sync_impl::Body;
22
23 use crate::common::init_test_work_runtime;
24
25 /// SDV test cases for `sync::Client`.
26 ///
27 /// # Brief
28 /// 1. Creates a runtime to host the server.
29 /// 2. Creates a server within the runtime coroutine.
30 /// 3. Creates a sync::Client.
31 /// 4. The client sends a request to the the server.
32 /// 5. Verifies the response returned by the server.
33 /// 6. Shuts down the server.
34 #[test]
sdv_synchronized_client_send_request()35 fn sdv_synchronized_client_send_request() {
36 // `PUT` request.
37 sync_client_test_case!(
38 HTTP;
39 RuntimeThreads: 2,
40 Request: {
41 Method: "PUT",
42 Host: "http://127.0.0.1",
43 Header: "Host", "127.0.0.1",
44 Header: "Content-Length", "6",
45 Body: "Hello!",
46 },
47 Response: {
48 Status: 200,
49 Version: "HTTP/1.1",
50 Header: "Content-Length", "3",
51 Body: "Hi!",
52 },
53 );
54 }
55
56 /// SDV test cases for `sync::Client`.
57 ///
58 /// # Brief
59 /// 1. Creates a runtime to host the server.
60 /// 2. Creates a server within the runtime coroutine.
61 /// 3. Creates a sync::Client.
62 /// 4. The client sends requests to the the server repeatedly.
63 /// 5. Verifies each response returned by the server.
64 /// 6. Shuts down the server.
65 #[test]
sdv_synchronized_client_send_request_repeatedly()66 fn sdv_synchronized_client_send_request_repeatedly() {
67 sync_client_test_case!(
68 HTTP;
69 RuntimeThreads: 2,
70 Request: {
71 Method: "GET",
72 Host: "http://127.0.0.1",
73 Header: "Host", "127.0.0.1",
74 Header: "Content-Length", "6",
75 Body: "Hello!",
76 },
77 Response: {
78 Status: 201,
79 Version: "HTTP/1.1",
80 Header: "Content-Length", "11",
81 Body: "METHOD GET!",
82 },
83 Request: {
84 Method: "POST",
85 Host: "http://127.0.0.1",
86 Header: "Host", "127.0.0.1",
87 Header: "Content-Length", "6",
88 Body: "Hello!",
89 },
90 Response: {
91 Status: 201,
92 Version: "HTTP/1.1",
93 Header: "Content-Length", "12",
94 Body: "METHOD POST!",
95 },
96 );
97 }
98