Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Backward-compatible changes fail the golden tests #103

Open
julienrf opened this issue Feb 18, 2021 · 0 comments
Open

Backward-compatible changes fail the golden tests #103

julienrf opened this issue Feb 18, 2021 · 0 comments

Comments

@julienrf
Copy link

When we evolve a data type in a backward-compatible way (e.g., by adding or removing an optional property), the golden tests fail because the Arbitrary generators produce different values.

Instead, it would be useful to have tests that support backward-compatible evolutions of data types.

We have implemented it internally at Bestmile, I can make a PR if you are interested. In essence, when we create a new version of the data type, we keep the old golden files and add new golden files. The law we test is the following:

      goldenExamples.flatMap {
        _.traverse { case (encodedString, maybeValue) =>
          maybeValue match {
            case Some(value) =>
              // The golden file contains the current version of the resource.
              // We check that:
              // - encoding the `value` produces the same `encodedString`
              // - decoding the `encodedString` produces the `value`
              parser.decode[A](encodedString)(decode).map { decoded =>
                val decoding = isEqToProp(decoded <-> value)
                val encoding = isEqToProp(printJson(encode(value)) <-> encodedString)
                decoding && encoding
              }.toTry
            case None =>
              // The golden file contains an old version of the resource.
              // We check that:
              // - we can still decode it
              // - encoding and then decoding it produces the same value as
              //   when decoding the old version
              (
                for {
                  decodedOldValue <- parser.decode[A](encodedString)(decode)
                  decodedNewValue <- decode.decodeJson(encode(decodedOldValue))
                } yield isEqToProp(decodedOldValue <-> decodedNewValue)
              ).toTry
          }
        }
      }
@julienrf julienrf changed the title Backward-compatible changes fail the property Backward-compatible changes fail the golden tests Feb 18, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant