Unverified Commit a7e05dbe authored by Russell Cohen's avatar Russell Cohen Committed by GitHub
Browse files

order endpoint parameters deterministically (#2125)

parent bb5bbeb5
Loading
Loading
Loading
Loading
+10 −2
Original line number Diff line number Diff line
@@ -22,6 +22,7 @@ import software.amazon.smithy.rust.codegen.core.rustlang.rustTemplate
import software.amazon.smithy.rust.codegen.core.rustlang.writable
import software.amazon.smithy.rust.codegen.core.smithy.RuntimeConfig
import software.amazon.smithy.rust.codegen.core.smithy.RuntimeType
import software.amazon.smithy.rust.codegen.core.util.PANIC
import software.amazon.smithy.rust.codegen.core.util.dq
import software.amazon.smithy.rust.codegen.core.util.orNull

@@ -73,7 +74,8 @@ internal class EndpointTestGenerator(
                        )
                    }
                    testCase.expect.error.ifPresent { error ->
                        val expectedError = escape("expected error: $error [${testCase.documentation.orNull() ?: "no docs"}]")
                        val expectedError =
                            escape("expected error: $error [${testCase.documentation.orNull() ?: "no docs"}]")
                        rustTemplate(
                            """
                            let error = endpoint.expect_err(${expectedError.dq()});
@@ -116,6 +118,7 @@ internal class EndpointTestGenerator(
                        }.join(","),
                    )
                }
                is Value.Integer -> rust(value.expectInteger().toString())

                is Value.Record ->
                    rustBlock("") {
@@ -123,7 +126,11 @@ internal class EndpointTestGenerator(
                            "let mut out = #{HashMap}::<String, #{Document}>::new();",
                            *codegenScope,
                        )
                        value.forEach { identifier, v ->
                        // TODO(https://github.com/awslabs/smithy/pull/1555): remove when this is released
                        val keys = mutableListOf<Identifier>()
                        value.forEach { id, _ -> keys.add(id) }
                        keys.sortedBy { it.name.value }.forEach { identifier ->
                            val v = value.get(identifier)
                            rust(
                                "out.insert(${identifier.toString().dq()}.to_string(), #W.into());",
                                // When writing into the hashmap, it always needs to be an owned type
@@ -132,6 +139,7 @@ internal class EndpointTestGenerator(
                        }
                        rustTemplate("out")
                    }
                else -> PANIC("unexpected type: $value")
            }
        }
    }
+1 −1
Original line number Diff line number Diff line
@@ -49,7 +49,7 @@ class LiteralGenerator(private val ownership: Ownership, private val context: Co
                "let mut out = #{HashMap}::<String, #{Document}>::new();",
                *codegenScope,
            )
            members.forEach { (identifier, literal) ->
            members.keys.sortedBy { it.toString() }.map { k -> k to members[k]!! }.forEach { (identifier, literal) ->
                rust(
                    "out.insert(${identifier.toString().dq()}.to_string(), #W.into());",
                    // When writing into the hashmap, it always needs to be an owned type
+17 −1
Original line number Diff line number Diff line
@@ -42,7 +42,15 @@ class EndpointsDecoratorTest {
                ],
                "type": "endpoint",
                "endpoint": {
                    "url": "https://www.{Region}.example.com"
                    "url": "https://www.{Region}.example.com",
                    "properties": {
                        "first-properties": {
                            "z-first": "zazz",
                            "y-second": "bar",
                            "x-third": "baz"
                        },
                        "second-properties": [1,2,3]
                    }
                }
            }],
            "parameters": {
@@ -73,6 +81,14 @@ class EndpointsDecoratorTest {
              "expect": {
                "endpoint": {
                    "url": "https://failingtest.com"
                    "properties": {
                        "first-properties": {
                            "a-first": "zazz",
                            "b-second": "bar",
                            "c-third": "baz"
                        },
                        "second-properties": [1,2,3]
                    }
                }
              }
            }