You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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 {
caseSome(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 =>valdecoding= isEqToProp(decoded <-> value)
valencoding= isEqToProp(printJson(encode(value)) <-> encodedString)
decoding && encoding
}.toTry
caseNone=>// 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
}
}
}
The text was updated successfully, but these errors were encountered:
julienrf
changed the title
Backward-compatible changes fail the property
Backward-compatible changes fail the golden tests
Feb 18, 2021
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:
The text was updated successfully, but these errors were encountered: