@@ -535,6 +535,14 @@ func TestValueFromMsgPack(t *testing.T) {
535535 }),
536536 typ : List {ElementType : DynamicPseudoType },
537537 },
538+ // This encoding, while unlikely in practice, is supported. Terraform should collapse this to a known null value before reaching providers.
539+ "unknown-with-nullness-true" : {
540+ hex : "c7030c8101c3" ,
541+ value : NewValue (Bool , UnknownValue ).Refine (refinement.Refinements {
542+ refinement .KeyNullness : refinement .NewNullness (true ),
543+ }),
544+ typ : Bool ,
545+ },
538546 "unknown-bool-with-nullness-refinement" : {
539547 hex : "c7030c8101c2" ,
540548 value : NewValue (Bool , UnknownValue ).Refine (refinement.Refinements {
@@ -671,9 +679,54 @@ func TestValueFromMsgPack(t *testing.T) {
671679 })
672680 }
673681}
682+ func TestValueFromMsgPack_refinements (t * testing.T ) {
683+ t .Parallel ()
684+
685+ tests := map [string ]struct {
686+ hex string
687+ expectedValue Value
688+ typ Type
689+ }{
690+ "unsupported-refinement-on-bool" : {
691+ // This hex value encodes the Nullness refinement as Key(100), which doesn't exist and should be ignored.
692+ hex : "c7030c8164c2" ,
693+ expectedValue : NewValue (Bool , UnknownValue ),
694+ typ : Bool ,
695+ },
696+ "unsupported-refinement-on-prefixed-string" : {
697+ // This hex value encodes the Nullness refinement as Key(100), which doesn't exist and should be ignored.
698+ // The hex value also includes a valid string prefix which should be preserved.
699+ hex : "c70e0c8264c202a97072656669783a2f2f" ,
700+ expectedValue : NewValue (String , UnknownValue ).Refine (refinement.Refinements {
701+ refinement .KeyStringPrefix : refinement .NewStringPrefix ("prefix://" ),
702+ }),
703+ typ : String ,
704+ },
705+ }
706+ for name , test := range tests {
707+ name , test := name , test
708+ t .Run (name , func (t * testing.T ) {
709+ t .Parallel ()
710+
711+ b , err := hex .DecodeString (test .hex )
712+ if err != nil {
713+ t .Fatalf ("unexpected error parsing hex: %s" , err )
714+ }
715+
716+ val , err := ValueFromMsgPack (b , test .typ )
717+ if err != nil {
718+ t .Fatalf ("unexpected error unmarshaling: %s" , err )
719+ }
720+
721+ if test .expectedValue .String () != val .String () {
722+ t .Errorf ("Unexpected results (-wanted +got): %s" , cmp .Diff (test .expectedValue , val ))
723+ }
724+ })
725+ }
726+ }
674727
675728// This test covers certain scenarios where we ignore refinement data during marshalling that are either invalid or not needed.
676- func TestMarshalMsgPack_refinement_exceptions (t * testing.T ) {
729+ func TestMarshalMsgPack_refinements (t * testing.T ) {
677730 t .Parallel ()
678731
679732 // Hex encoding of the long prefix refinements that are eventually truncated in this test
0 commit comments