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

Add codegen-serde unit tests to CI (#4314)

This PR adds the codegen-serde module to the GitHub Actions test matrix
& fixes broken tests.

Along the way, I found some broken tests which I also fixed.

## Changes
- Added `check-serde-codegen-unit-tests` script in `tools/ci-scripts/`
- Added corresponding target to `ci.mk`
- Added the test to the GitHub Actions workflow matrix in
`.github/workflows/ci.yml`

This follows the same pattern as other codegen unit test modules
(codegen-core, codegen-client, codegen-server) and ensures that
codegen-serde tests are run as part of CI.
parent 1c192f83
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -110,6 +110,8 @@ jobs:
          runner: ubuntu-latest
        - action: check-server-codegen-unit-tests-python
          runner: ubuntu-latest
        - action: check-serde-codegen-unit-tests
          runner: ubuntu-latest
        - action: check-server-e2e-test
          runner: ubuntu-latest
        - action: check-server-python-e2e-test
+4 −0
Original line number Diff line number Diff line
@@ -84,6 +84,10 @@ check-server-codegen-integration-tests:
check-server-codegen-unit-tests:
	$(CI_ACTION) $@ $(ARGS)

.PHONY: check-serde-codegen-unit-tests
check-serde-codegen-unit-tests:
	$(CI_ACTION) $@ $(ARGS)

.PHONY: check-server-codegen-integration-tests-python
check-server-codegen-integration-tests-python:
	$(CI_ACTION) $@ $(ARGS)
+2 −2
Original line number Diff line number Diff line
@@ -544,7 +544,7 @@ class SerializeImplGenerator(private val codegenContext: CodegenContext) {
    ) {
        rustTemplate(
            """
            impl<'a> #{serde}::Serialize for #{ConfigurableSerdeRef}<'a, #{Shape}> {
            impl #{serde}::Serialize for #{ConfigurableSerdeRef}<'_, #{Shape}> {
                fn serialize<S>(&self, serializer: S) -> #{Result}<S::Ok, S::Error>
                where
                    S: #{serde}::Serializer,
@@ -567,7 +567,7 @@ class SerializeImplGenerator(private val codegenContext: CodegenContext) {
        return writable {
            rustTemplate(
                """
                impl<'a, 'b> #{serde}::Serialize for #{ConfigurableSerdeRef}<'a, #{Shape}<'b>> {
                impl #{serde}::Serialize for #{ConfigurableSerdeRef}<'_, #{Shape}<'_>> {
                    fn serialize<S>(&self, serializer: S) -> #{Result}<S::Ok, S::Error>
                    where
                        S: #{serde}::Serializer,
+3 −3
Original line number Diff line number Diff line
@@ -133,7 +133,7 @@ object SupportStructures {
                """
                pub(crate) struct Sensitive<T>(pub(crate) T);

                impl<'a, T> #{serde}::Serialize for ConfigurableSerdeRef<'a, Sensitive<T>>
                impl<T> #{serde}::Serialize for ConfigurableSerdeRef<'_, Sensitive<T>>
                where
                T: #{serde}::Serialize,
                {
@@ -175,7 +175,7 @@ object SupportStructures {
                        .serialize(serializer)
                    }
                }
                impl<'a, T> #{serde}::Serialize for #{ConfigurableSerdeRef}<'a, Option<T>>
                impl<T> #{serde}::Serialize for #{ConfigurableSerdeRef}<'_, Option<T>>
                where
                    T: #{SerializeConfigured},
                {
@@ -235,7 +235,7 @@ object SupportStructures {
                    ///
                    /// Note: This may alter the type of the serialized output and make it impossible to deserialize as
                    /// numerical fields will be replaced with strings.
                    pub const fn redact_sensitive_fields() -> Self { Self { redact_sensitive_fields: true, out_of_range_floats_as_strings: false } }
                    pub const fn redact_sensitive_fields() -> Self { Self { redact_sensitive_fields: true, out_of_range_floats_as_strings: true } }

                    /// Preserve the contents of sensitive fields during serializing
                    pub const fn leak_sensitive_fields() -> Self { Self { redact_sensitive_fields: false, out_of_range_floats_as_strings: false } }
+2 −0
Original line number Diff line number Diff line
@@ -255,6 +255,7 @@ class SerdeDecoratorTest {
            IntegrationTestParams(cargoCommand = "cargo test --all-features", service = "com.example#MyService")
        serverIntegrationTest(model, params = params) { _, crate ->
            crate.integrationTest("test_serde") {
                rust("##![allow(unexpected_cfgs)]")
                unitTest("fails_if_serde_feature_exists", additionalAttributes = listOf(Attribute(cfg(feature("serde"))))) {
                    rust("assert!(false);")
                }
@@ -347,6 +348,7 @@ class SerdeDecoratorTest {
                            .build()
                            .unwrap();
                        let mut settings = SerializationSettings::default();
                        settings.out_of_range_floats_as_strings = true;
                        let serialized = #{serde_json}::to_string(&input.serialize_ref(&settings)).expect("failed to serialize");
                        assert_eq!(serialized, ${expectedNoRedactions.dq()});
                        settings.redact_sensitive_fields = true;
Loading