Struct SyntheticsAssertionJavascript

Source
#[non_exhaustive]
pub struct SyntheticsAssertionJavascript { pub code: String, pub type_: SyntheticsAssertionJavascriptType, pub additional_properties: BTreeMap<String, Value>, /* private fields */ }
Expand description

A JavaScript assertion.

Fields (Non-exhaustive)§

This struct is marked as non-exhaustive
Non-exhaustive structs could have additional fields added in future. Therefore, non-exhaustive structs cannot be constructed in external crates using the traditional Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.
§code: String

The JavaScript code that performs the assertions.

§type_: SyntheticsAssertionJavascriptType

Type of the assertion.

§additional_properties: BTreeMap<String, Value>

Implementations§

Source§

impl SyntheticsAssertionJavascript

Source

pub fn new( code: String, type_: SyntheticsAssertionJavascriptType, ) -> SyntheticsAssertionJavascript

Examples found in repository?
examples/v1_synthetics_CreateSyntheticsAPITest_1487281163.rs (lines 153-156)
46async fn main() {
47    let body =
48        SyntheticsAPITest::new(
49            SyntheticsAPITestConfig::new()
50                .assertions(
51                    vec![
52                        SyntheticsAssertion::SyntheticsAssertionTarget(
53                            Box::new(
54                                SyntheticsAssertionTarget::new(
55                                    SyntheticsAssertionOperator::IS,
56                                    SyntheticsAssertionTargetValue::SyntheticsAssertionTargetValueString(
57                                        "text/html".to_string(),
58                                    ),
59                                    SyntheticsAssertionType::HEADER,
60                                ).property("{{ PROPERTY }}".to_string()),
61                            ),
62                        ),
63                        SyntheticsAssertion::SyntheticsAssertionTarget(
64                            Box::new(
65                                SyntheticsAssertionTarget::new(
66                                    SyntheticsAssertionOperator::LESS_THAN,
67                                    SyntheticsAssertionTargetValue::SyntheticsAssertionTargetValueNumber(
68                                        2000.0 as f64,
69                                    ),
70                                    SyntheticsAssertionType::RESPONSE_TIME,
71                                ).timings_scope(SyntheticsAssertionTimingsScope::WITHOUT_DNS),
72                            ),
73                        ),
74                        SyntheticsAssertion::SyntheticsAssertionJSONPathTarget(
75                            Box::new(
76                                SyntheticsAssertionJSONPathTarget::new(
77                                    SyntheticsAssertionJSONPathOperator::VALIDATES_JSON_PATH,
78                                    SyntheticsAssertionType::BODY,
79                                ).target(
80                                    SyntheticsAssertionJSONPathTargetTarget::new()
81                                        .json_path("topKey".to_string())
82                                        .operator("isNot".to_string())
83                                        .target_value(
84                                            SyntheticsAssertionTargetValue::SyntheticsAssertionTargetValueString(
85                                                "0".to_string(),
86                                            ),
87                                        ),
88                                ),
89                            ),
90                        ),
91                        SyntheticsAssertion::SyntheticsAssertionJSONPathTarget(
92                            Box::new(
93                                SyntheticsAssertionJSONPathTarget::new(
94                                    SyntheticsAssertionJSONPathOperator::VALIDATES_JSON_PATH,
95                                    SyntheticsAssertionType::BODY,
96                                ).target(
97                                    SyntheticsAssertionJSONPathTargetTarget::new()
98                                        .elements_operator("atLeastOneElementMatches".to_string())
99                                        .json_path("topKey".to_string())
100                                        .operator("isNot".to_string())
101                                        .target_value(
102                                            SyntheticsAssertionTargetValue::SyntheticsAssertionTargetValueString(
103                                                "0".to_string(),
104                                            ),
105                                        ),
106                                ),
107                            ),
108                        ),
109                        SyntheticsAssertion::SyntheticsAssertionJSONSchemaTarget(
110                            Box::new(
111                                SyntheticsAssertionJSONSchemaTarget::new(
112                                    SyntheticsAssertionJSONSchemaOperator::VALIDATES_JSON_SCHEMA,
113                                    SyntheticsAssertionType::BODY,
114                                ).target(
115                                    SyntheticsAssertionJSONSchemaTargetTarget::new()
116                                        .json_schema(
117                                            r#"{"type": "object", "properties":{"slideshow":{"type":"object"}}}"#.to_string(),
118                                        )
119                                        .meta_schema(SyntheticsAssertionJSONSchemaMetaSchema::DRAFT_07),
120                                ),
121                            ),
122                        ),
123                        SyntheticsAssertion::SyntheticsAssertionXPathTarget(
124                            Box::new(
125                                SyntheticsAssertionXPathTarget::new(
126                                    SyntheticsAssertionXPathOperator::VALIDATES_X_PATH,
127                                    SyntheticsAssertionType::BODY,
128                                ).target(
129                                    SyntheticsAssertionXPathTargetTarget::new()
130                                        .operator("contains".to_string())
131                                        .target_value(
132                                            SyntheticsAssertionTargetValue::SyntheticsAssertionTargetValueString(
133                                                "0".to_string(),
134                                            ),
135                                        )
136                                        .x_path("target-xpath".to_string()),
137                                ),
138                            ),
139                        ),
140                        SyntheticsAssertion::SyntheticsAssertionBodyHashTarget(
141                            Box::new(
142                                SyntheticsAssertionBodyHashTarget::new(
143                                    SyntheticsAssertionBodyHashOperator::MD5,
144                                    SyntheticsAssertionTargetValue::SyntheticsAssertionTargetValueString(
145                                        "a".to_string(),
146                                    ),
147                                    SyntheticsAssertionBodyHashType::BODY_HASH,
148                                ),
149                            ),
150                        ),
151                        SyntheticsAssertion::SyntheticsAssertionJavascript(
152                            Box::new(
153                                SyntheticsAssertionJavascript::new(
154                                    "const hello = 'world';".to_string(),
155                                    SyntheticsAssertionJavascriptType::JAVASCRIPT,
156                                ),
157                            ),
158                        )
159                    ],
160                )
161                .config_variables(
162                    vec![
163                        SyntheticsConfigVariable::new("PROPERTY".to_string(), SyntheticsConfigVariableType::TEXT)
164                            .example("content-type".to_string())
165                            .pattern("content-type".to_string())
166                    ],
167                )
168                .request(
169                    SyntheticsTestRequest::new()
170                        .basic_auth(
171                            SyntheticsBasicAuth::SyntheticsBasicAuthOauthClient(
172                                Box::new(
173                                    SyntheticsBasicAuthOauthClient::new(
174                                        "https://datadog-token.com".to_string(),
175                                        "client-id".to_string(),
176                                        "client-secret".to_string(),
177                                        SyntheticsBasicAuthOauthTokenApiAuthentication::HEADER,
178                                        SyntheticsBasicAuthOauthClientType::OAUTH_CLIENT,
179                                    )
180                                        .audience("audience".to_string())
181                                        .resource("resource".to_string())
182                                        .scope("yoyo".to_string()),
183                                ),
184                            ),
185                        )
186                        .certificate(
187                            SyntheticsTestRequestCertificate::new()
188                                .cert(
189                                    SyntheticsTestRequestCertificateItem::new()
190                                        .content("cert-content".to_string())
191                                        .filename("cert-filename".to_string())
192                                        .updated_at("2020-10-16T09:23:24.857Z".to_string()),
193                                )
194                                .key(
195                                    SyntheticsTestRequestCertificateItem::new()
196                                        .content("key-content".to_string())
197                                        .filename("key-filename".to_string())
198                                        .updated_at("2020-10-16T09:23:24.857Z".to_string()),
199                                ),
200                        )
201                        .headers(BTreeMap::from([("unique".to_string(), "examplesynthetic".to_string())]))
202                        .method("GET".to_string())
203                        .persist_cookies(true)
204                        .proxy(
205                            SyntheticsTestRequestProxy::new(
206                                "https://datadoghq.com".to_string(),
207                            ).headers(BTreeMap::from([])),
208                        )
209                        .timeout(10.0 as f64)
210                        .url("https://datadoghq.com".to_string()),
211                )
212                .variables_from_script(r#"dd.variable.set("FOO", "foo")"#.to_string()),
213            vec!["aws:us-east-2".to_string()],
214            "BDD test payload: synthetics_api_http_test_payload.json".to_string(),
215            "Example-Synthetic".to_string(),
216            SyntheticsTestOptions::new()
217                .accept_self_signed(false)
218                .allow_insecure(true)
219                .follow_redirects(true)
220                .http_version(SyntheticsTestOptionsHTTPVersion::HTTP2)
221                .min_failure_duration(10)
222                .min_location_failed(1)
223                .monitor_name("Example-Synthetic".to_string())
224                .monitor_priority(5)
225                .retry(SyntheticsTestOptionsRetry::new().count(3).interval(10.0 as f64))
226                .tick_every(60),
227            SyntheticsAPITestType::API,
228        )
229            .subtype(SyntheticsTestDetailsSubType::HTTP)
230            .tags(vec!["testing:api".to_string()]);
231    let configuration = datadog::Configuration::new();
232    let api = SyntheticsAPI::with_config(configuration);
233    let resp = api.create_synthetics_api_test(body).await;
234    if let Ok(value) = resp {
235        println!("{:#?}", value);
236    } else {
237        println!("{:#?}", resp.unwrap_err());
238    }
239}
More examples
Hide additional examples
examples/v1_synthetics_CreateSyntheticsAPITest_1987645492.rs (lines 152-155)
45async fn main() {
46    let body =
47        SyntheticsAPITest::new(
48            SyntheticsAPITestConfig::new()
49                .assertions(
50                    vec![
51                        SyntheticsAssertion::SyntheticsAssertionTarget(
52                            Box::new(
53                                SyntheticsAssertionTarget::new(
54                                    SyntheticsAssertionOperator::IS,
55                                    SyntheticsAssertionTargetValue::SyntheticsAssertionTargetValueString(
56                                        "text/html".to_string(),
57                                    ),
58                                    SyntheticsAssertionType::HEADER,
59                                ).property("{{ PROPERTY }}".to_string()),
60                            ),
61                        ),
62                        SyntheticsAssertion::SyntheticsAssertionTarget(
63                            Box::new(
64                                SyntheticsAssertionTarget::new(
65                                    SyntheticsAssertionOperator::LESS_THAN,
66                                    SyntheticsAssertionTargetValue::SyntheticsAssertionTargetValueNumber(
67                                        2000.0 as f64,
68                                    ),
69                                    SyntheticsAssertionType::RESPONSE_TIME,
70                                ).timings_scope(SyntheticsAssertionTimingsScope::WITHOUT_DNS),
71                            ),
72                        ),
73                        SyntheticsAssertion::SyntheticsAssertionJSONPathTarget(
74                            Box::new(
75                                SyntheticsAssertionJSONPathTarget::new(
76                                    SyntheticsAssertionJSONPathOperator::VALIDATES_JSON_PATH,
77                                    SyntheticsAssertionType::BODY,
78                                ).target(
79                                    SyntheticsAssertionJSONPathTargetTarget::new()
80                                        .json_path("topKey".to_string())
81                                        .operator("isNot".to_string())
82                                        .target_value(
83                                            SyntheticsAssertionTargetValue::SyntheticsAssertionTargetValueString(
84                                                "0".to_string(),
85                                            ),
86                                        ),
87                                ),
88                            ),
89                        ),
90                        SyntheticsAssertion::SyntheticsAssertionJSONPathTarget(
91                            Box::new(
92                                SyntheticsAssertionJSONPathTarget::new(
93                                    SyntheticsAssertionJSONPathOperator::VALIDATES_JSON_PATH,
94                                    SyntheticsAssertionType::BODY,
95                                ).target(
96                                    SyntheticsAssertionJSONPathTargetTarget::new()
97                                        .elements_operator("atLeastOneElementMatches".to_string())
98                                        .json_path("topKey".to_string())
99                                        .operator("isNot".to_string())
100                                        .target_value(
101                                            SyntheticsAssertionTargetValue::SyntheticsAssertionTargetValueString(
102                                                "0".to_string(),
103                                            ),
104                                        ),
105                                ),
106                            ),
107                        ),
108                        SyntheticsAssertion::SyntheticsAssertionJSONSchemaTarget(
109                            Box::new(
110                                SyntheticsAssertionJSONSchemaTarget::new(
111                                    SyntheticsAssertionJSONSchemaOperator::VALIDATES_JSON_SCHEMA,
112                                    SyntheticsAssertionType::BODY,
113                                ).target(
114                                    SyntheticsAssertionJSONSchemaTargetTarget::new()
115                                        .json_schema(
116                                            r#"{"type": "object", "properties":{"slideshow":{"type":"object"}}}"#.to_string(),
117                                        )
118                                        .meta_schema(SyntheticsAssertionJSONSchemaMetaSchema::DRAFT_07),
119                                ),
120                            ),
121                        ),
122                        SyntheticsAssertion::SyntheticsAssertionXPathTarget(
123                            Box::new(
124                                SyntheticsAssertionXPathTarget::new(
125                                    SyntheticsAssertionXPathOperator::VALIDATES_X_PATH,
126                                    SyntheticsAssertionType::BODY,
127                                ).target(
128                                    SyntheticsAssertionXPathTargetTarget::new()
129                                        .operator("contains".to_string())
130                                        .target_value(
131                                            SyntheticsAssertionTargetValue::SyntheticsAssertionTargetValueString(
132                                                "0".to_string(),
133                                            ),
134                                        )
135                                        .x_path("target-xpath".to_string()),
136                                ),
137                            ),
138                        ),
139                        SyntheticsAssertion::SyntheticsAssertionBodyHashTarget(
140                            Box::new(
141                                SyntheticsAssertionBodyHashTarget::new(
142                                    SyntheticsAssertionBodyHashOperator::MD5,
143                                    SyntheticsAssertionTargetValue::SyntheticsAssertionTargetValueString(
144                                        "a".to_string(),
145                                    ),
146                                    SyntheticsAssertionBodyHashType::BODY_HASH,
147                                ),
148                            ),
149                        ),
150                        SyntheticsAssertion::SyntheticsAssertionJavascript(
151                            Box::new(
152                                SyntheticsAssertionJavascript::new(
153                                    "const hello = 'world';".to_string(),
154                                    SyntheticsAssertionJavascriptType::JAVASCRIPT,
155                                ),
156                            ),
157                        )
158                    ],
159                )
160                .config_variables(
161                    vec![
162                        SyntheticsConfigVariable::new("PROPERTY".to_string(), SyntheticsConfigVariableType::TEXT)
163                            .example("content-type".to_string())
164                            .pattern("content-type".to_string())
165                    ],
166                )
167                .request(
168                    SyntheticsTestRequest::new()
169                        .basic_auth(
170                            SyntheticsBasicAuth::SyntheticsBasicAuthOauthClient(
171                                Box::new(
172                                    SyntheticsBasicAuthOauthClient::new(
173                                        "https://datadog-token.com".to_string(),
174                                        "client-id".to_string(),
175                                        "client-secret".to_string(),
176                                        SyntheticsBasicAuthOauthTokenApiAuthentication::HEADER,
177                                        SyntheticsBasicAuthOauthClientType::OAUTH_CLIENT,
178                                    )
179                                        .audience("audience".to_string())
180                                        .resource("resource".to_string())
181                                        .scope("yoyo".to_string()),
182                                ),
183                            ),
184                        )
185                        .certificate(
186                            SyntheticsTestRequestCertificate::new()
187                                .cert(
188                                    SyntheticsTestRequestCertificateItem::new()
189                                        .content("cert-content".to_string())
190                                        .filename("cert-filename".to_string())
191                                        .updated_at("2020-10-16T09:23:24.857Z".to_string()),
192                                )
193                                .key(
194                                    SyntheticsTestRequestCertificateItem::new()
195                                        .content("key-content".to_string())
196                                        .filename("key-filename".to_string())
197                                        .updated_at("2020-10-16T09:23:24.857Z".to_string()),
198                                ),
199                        )
200                        .headers(BTreeMap::from([("unique".to_string(), "examplesynthetic".to_string())]))
201                        .method("GET".to_string())
202                        .persist_cookies(true)
203                        .proxy(
204                            SyntheticsTestRequestProxy::new(
205                                "https://datadoghq.com".to_string(),
206                            ).headers(BTreeMap::from([])),
207                        )
208                        .timeout(10.0 as f64)
209                        .url("https://datadoghq.com".to_string()),
210                )
211                .variables_from_script(r#"dd.variable.set("FOO", "foo")"#.to_string()),
212            vec!["aws:us-east-2".to_string()],
213            "BDD test payload: synthetics_api_http_test_payload.json".to_string(),
214            "Example-Synthetic".to_string(),
215            SyntheticsTestOptions::new()
216                .accept_self_signed(false)
217                .allow_insecure(true)
218                .follow_redirects(true)
219                .http_version(SyntheticsTestOptionsHTTPVersion::HTTP2)
220                .min_failure_duration(10)
221                .min_location_failed(1)
222                .monitor_name("Example-Synthetic".to_string())
223                .monitor_priority(5)
224                .retry(SyntheticsTestOptionsRetry::new().count(3).interval(10.0 as f64))
225                .tick_every(60),
226            SyntheticsAPITestType::API,
227        )
228            .subtype(SyntheticsTestDetailsSubType::HTTP)
229            .tags(vec!["testing:api".to_string()]);
230    let configuration = datadog::Configuration::new();
231    let api = SyntheticsAPI::with_config(configuration);
232    let resp = api.create_synthetics_api_test(body).await;
233    if let Ok(value) = resp {
234        println!("{:#?}", value);
235    } else {
236        println!("{:#?}", resp.unwrap_err());
237    }
238}
Source

pub fn additional_properties(self, value: BTreeMap<String, Value>) -> Self

Trait Implementations§

Source§

impl Clone for SyntheticsAssertionJavascript

Source§

fn clone(&self) -> SyntheticsAssertionJavascript

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for SyntheticsAssertionJavascript

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'de> Deserialize<'de> for SyntheticsAssertionJavascript

Source§

fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl PartialEq for SyntheticsAssertionJavascript

Source§

fn eq(&self, other: &SyntheticsAssertionJavascript) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Serialize for SyntheticsAssertionJavascript

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl StructuralPartialEq for SyntheticsAssertionJavascript

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

impl<T> ErasedDestructor for T
where T: 'static,