Skip to content

Commit b35d179

Browse files
committed
add some initial tests
1 parent 78c8d98 commit b35d179

File tree

1 file changed

+56
-0
lines changed

1 file changed

+56
-0
lines changed

tftypes/value_msgpack_test.go

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
"testing"
1111

1212
"github.com/google/go-cmp/cmp"
13+
"github.com/hashicorp/terraform-plugin-go/tftypes/refinement"
1314
)
1415

1516
func TestValueFromMsgPack(t *testing.T) {
@@ -532,6 +533,60 @@ func TestValueFromMsgPack(t *testing.T) {
532533
}),
533534
typ: List{ElementType: DynamicPseudoType},
534535
},
536+
"unknown-string-with-refinements": {
537+
// TODO: How to actually visualize this? So hard to read these tests...
538+
hex: "c70e0c8201c202a97072656669783a2f2f",
539+
value: NewValue(String, UnknownValue).Refine(refinement.Refinements{
540+
refinement.KeyNullness: refinement.NewNullness(false),
541+
refinement.KeyStringPrefix: refinement.NewStringPrefix("prefix://"),
542+
}),
543+
typ: String,
544+
},
545+
"unknown-number-with-refinements": {
546+
// TODO: How to actually visualize this? So hard to read these tests...
547+
hex: "c70b0c8301c2039201c3049205c3",
548+
value: NewValue(Number, UnknownValue).Refine(refinement.Refinements{
549+
refinement.KeyNullness: refinement.NewNullness(false),
550+
refinement.KeyNumberLowerBound: refinement.NewNumberLowerBound(big.NewFloat(1), true),
551+
refinement.KeyNumberUpperBound: refinement.NewNumberUpperBound(big.NewFloat(5), true),
552+
}),
553+
typ: Number,
554+
},
555+
"unknown-list-with-refinements": {
556+
// TODO: How to actually visualize this? So hard to read these tests...
557+
hex: "c7070c8301c205010605",
558+
value: NewValue(List{ElementType: String}, UnknownValue).Refine(refinement.Refinements{
559+
refinement.KeyNullness: refinement.NewNullness(false),
560+
refinement.KeyCollectionLengthLowerBound: refinement.NewCollectionLengthLowerBound(1),
561+
refinement.KeyCollectionLengthUpperBound: refinement.NewCollectionLengthUpperBound(5),
562+
}),
563+
typ: List{ElementType: String},
564+
},
565+
"unknown-map-with-refinements": {
566+
// TODO: How to actually visualize this? So hard to read these tests...
567+
hex: "c7070c8301c205010605",
568+
value: NewValue(Map{ElementType: String}, UnknownValue).Refine(refinement.Refinements{
569+
refinement.KeyNullness: refinement.NewNullness(false),
570+
refinement.KeyCollectionLengthLowerBound: refinement.NewCollectionLengthLowerBound(1),
571+
refinement.KeyCollectionLengthUpperBound: refinement.NewCollectionLengthUpperBound(5),
572+
}),
573+
typ: Map{ElementType: String},
574+
},
575+
"unknown-set-with-refinements": {
576+
// TODO: How to actually visualize this? So hard to read these tests...
577+
hex: "c7070c8301c205010605",
578+
value: NewValue(Set{ElementType: String}, UnknownValue).Refine(refinement.Refinements{
579+
refinement.KeyNullness: refinement.NewNullness(false),
580+
refinement.KeyCollectionLengthLowerBound: refinement.NewCollectionLengthLowerBound(1),
581+
refinement.KeyCollectionLengthUpperBound: refinement.NewCollectionLengthUpperBound(5),
582+
}),
583+
typ: Set{ElementType: String},
584+
},
585+
// TODO: Test putting refinements with too long of data (string prefix over 256)
586+
// TODO: Test putting refinements with incorrect data (string prefix on nullness key)
587+
// TODO: Test putting refinements on incorrect types (prefix on number or boolean)
588+
// TODO: Test refinement number that doesn't exist? Should just be unknown value
589+
// TODO: Test DynamicPseudoType?
535590
}
536591
for name, test := range tests {
537592
name, test := name, test
@@ -550,6 +605,7 @@ func TestValueFromMsgPack(t *testing.T) {
550605
if err != nil {
551606
t.Fatalf("unexpected error parsing hex: %s", err)
552607
}
608+
553609
val, err := ValueFromMsgPack(b, test.typ)
554610
if err != nil {
555611
t.Fatalf("unexpected error unmarshaling: %s", err)

0 commit comments

Comments
 (0)