Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "feature",
"description": "Update smithy-rules-engine-tests with new std lib functions and bdd-based tests",
"pull_requests": [
"[#2945](https://github.com/smithy-lang/smithy/pull/2945)"
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,167 @@
$version: "2.0"

namespace smithy.rules.tests

use smithy.rules#clientContextParams
use smithy.rules#endpointRuleSet
use smithy.rules#endpointTests

@suppress(["UnstableTrait", "RuleSetParameter.TestCase.Unused"])
@clientContextParams(
TestCaseId: { type: "string", required: true, documentation: "Test case id used to select the test case to use" }
req1: { type: "string", documentation: "docs" }
req2: { type: "string", documentation: "docs" }
opt1: { type: "string", documentation: "always Some" }
opt2: { type: "string", documentation: "always Some" }
)
@endpointRuleSet({
version: "1.1"
parameters: {
TestCaseId: { type: "string", required: true, documentation: "Test case id used to select the test case to use" }
req1: { type: "string", documentation: "req1", required: true, default: "req1Value" }
req2: { type: "string", documentation: "req2", required: true, default: "req2Value" }
opt1: { type: "string", documentation: "opt1" }
opt2: { type: "string", documentation: "opt2" }
}
rules: [
{
documentation: "Two required"
conditions: [
{
fn: "stringEquals"
argv: ["{TestCaseId}", "0"]
}
{
fn: "coalesce"
argv: [
{
ref: "req1"
}
{
ref: "req2"
}
]
assign: "req1req2"
}
]
error: "The value is: {req1req2}"
type: "error"
}
{
documentation: "Two optional"
conditions: [
{
fn: "stringEquals"
argv: ["{TestCaseId}", "1"]
}
{
fn: "coalesce"
argv: [
{
ref: "opt1"
}
{
ref: "opt2"
}
]
assign: "opt1opt2"
}
]
error: "The value is: {opt1opt2}"
type: "error"
}
{
documentation: "Required then Optional"
conditions: [
{
fn: "stringEquals"
argv: ["{TestCaseId}", "2"]
}
{
fn: "coalesce"
argv: [
{
ref: "req1"
}
{
ref: "opt1"
}
]
assign: "req1opt1"
}
]
error: "The value is: {req1opt1}"
type: "error"
}
{
documentation: "Optional then Required"
conditions: [
{
fn: "stringEquals"
argv: ["{TestCaseId}", "3"]
}
{
fn: "coalesce"
argv: [
{
ref: "opt1"
}
{
ref: "req1"
}
]
assign: "opt1req1"
}
]
error: "The value is: {opt1req1}"
type: "error"
}
{
conditions: []
documentation: "error fallthrough"
error: "endpoint error"
type: "error"
}
]
})
@endpointTests({
version: "1.0"
testCases: [
{
documentation: "Two required, first val returned"
params: { TestCaseId: "0" }
expect: { error: "The value is: req1Value" }
}
{
documentation: "Two optional, Some(opt1Value), Some(opt2Value), opt1Value returned"
params: { TestCaseId: "1", opt1: "opt1Value", opt2: "opt2Value" }
expect: { error: "The value is: opt1Value" }
}
{
documentation: "Two optional, None, Some(opt2Value), opt2Value returned"
params: { TestCaseId: "1", opt2: "opt2Value" }
expect: { error: "The value is: opt2Value" }
}
{
documentation: "Two optional, None, None, None returned"
params: { TestCaseId: "1" }
expect: { error: "endpoint error" }
}
{
documentation: "Required then Optional, required returned"
params: { TestCaseId: "2", opt1: "opt1Value" }
expect: { error: "The value is: req1Value" }
}
{
documentation: "Optional then Required, optional value returned"
params: { TestCaseId: "3", opt1: "opt1Value" }
expect: { error: "The value is: opt1Value" }
}
{
documentation: "Optional then Required, optional is none so required value returned"
params: { TestCaseId: "3" }
expect: { error: "The value is: req1Value" }
}
]
})
service CoalesceTest {}
Original file line number Diff line number Diff line change
Expand Up @@ -8,98 +8,78 @@ use smithy.rules#endpointTests

@suppress(["UnstableTrait"])
@clientContextParams(
bar: {type: "string", documentation: "a client string parameter"}
baz: {type: "string", documentation: "another client string parameter"}
bar: { type: "string", documentation: "a client string parameter" }
baz: { type: "string", documentation: "another client string parameter" }
)
@endpointRuleSet({
version: "1.0",
version: "1.0"
parameters: {
bar: {
type: "string",
documentation: "docs"
}
baz: {
type: "string",
documentation: "docs"
required: true
default: "baz"
}
},
bar: { type: "string", documentation: "docs" }
baz: { type: "string", documentation: "docs", required: true, default: "baz" }
}
rules: [
{
"conditions": [
conditions: [
{
"fn": "isSet",
"argv": [
fn: "isSet"
argv: [
{
"ref": "bar"
ref: "bar"
}
]
}
],
"endpoint": {
"url": "https://example.com/{baz}"
},
"type": "endpoint"
},
]
endpoint: { url: "https://example.com/{baz}" }
type: "endpoint"
}
{
"conditions": [],
"documentation": "error fallthrough",
"error": "endpoint error",
"type": "error"
conditions: []
documentation: "error fallthrough"
error: "endpoint error"
type: "error"
}
]
})
@endpointTests({
"version": "1.0",
"testCases": [
version: "1.0"
testCases: [
{
"documentation": "Default value is used when parameter is unset",
"params": {
"bar": "a b",
}
"operationInputs": [{
"operationName": "GetThing",
"clientParams": {
"bar": "a b"
}
}],
"expect": {
"endpoint": {
"url": "https://example.com/baz"
documentation: "Default value is used when parameter is unset"
params: { bar: "a b" }
operationInputs: [
{
operationName: "GetThing"
clientParams: { bar: "a b" }
}
]
expect: {
endpoint: { url: "https://example.com/baz" }
}
},
}
{
"documentation": "Default value is not used when the parameter is set",
"params": {
"bar": "a b",
"baz": "BIG"
}
"operationInputs": [{
"operationName": "GetThing",
"clientParams": {
"bar": "a b",
"baz": "BIG"
}
}],
"expect": {
"endpoint": {
"url": "https://example.com/BIG"
documentation: "Default value is not used when the parameter is set"
params: { bar: "a b", baz: "BIG" }
operationInputs: [
{
operationName: "GetThing"
clientParams: { bar: "a b", baz: "BIG" }
}
]
expect: {
endpoint: { url: "https://example.com/BIG" }
}
},
}
{
"documentation": "a documentation string",
"expect": {
"error": "endpoint error"
}
documentation: "a documentation string"
expect: { error: "endpoint error" }
}
]
})
service DefaultValuesService {
version: "2022-01-01",
operations: [GetThing]
version: "2022-01-01"
operations: [
GetThing
]
}

operation GetThing {
Expand Down
Loading
Loading