@@ -19,28 +19,28 @@ func TestKeysAreValidator(t *testing.T) {
1919 type testCase struct {
2020 val attr.Value
2121 keysAreValidators []tfsdk.AttributeValidator
22- expectError bool
22+ expectErrorsCount int
2323 }
2424 tests := map [string ]testCase {
2525 "not Map" : {
2626 val : types.List {
2727 ElemType : types .StringType ,
2828 },
29- expectError : true ,
29+ expectErrorsCount : 1 ,
3030 },
3131 "Map unknown" : {
3232 val : types.Map {
3333 Unknown : true ,
3434 ElemType : types .StringType ,
3535 },
36- expectError : false ,
36+ expectErrorsCount : 0 ,
3737 },
3838 "Map null" : {
3939 val : types.Map {
4040 Null : true ,
4141 ElemType : types .StringType ,
4242 },
43- expectError : false ,
43+ expectErrorsCount : 0 ,
4444 },
4545 "Map key invalid" : {
4646 val : types.Map {
@@ -53,7 +53,7 @@ func TestKeysAreValidator(t *testing.T) {
5353 keysAreValidators : []tfsdk.AttributeValidator {
5454 stringvalidator .LengthAtLeast (4 ),
5555 },
56- expectError : true ,
56+ expectErrorsCount : 2 ,
5757 },
5858 "Map key invalid for second validator" : {
5959 val : types.Map {
@@ -67,7 +67,7 @@ func TestKeysAreValidator(t *testing.T) {
6767 stringvalidator .LengthAtLeast (2 ),
6868 stringvalidator .LengthAtLeast (6 ),
6969 },
70- expectError : true ,
70+ expectErrorsCount : 2 ,
7171 },
7272 "Map keys wrong type for validator" : {
7373 val : types.Map {
@@ -80,7 +80,20 @@ func TestKeysAreValidator(t *testing.T) {
8080 keysAreValidators : []tfsdk.AttributeValidator {
8181 int64validator .AtLeast (6 ),
8282 },
83- expectError : true ,
83+ expectErrorsCount : 1 ,
84+ },
85+ "Map keys for invalid multiple validators" : {
86+ val : types.Map {
87+ ElemType : types .StringType ,
88+ Elems : map [string ]attr.Value {
89+ "one" : types.String {Value : "first" },
90+ },
91+ },
92+ keysAreValidators : []tfsdk.AttributeValidator {
93+ stringvalidator .LengthAtLeast (5 ),
94+ stringvalidator .LengthAtLeast (6 ),
95+ },
96+ expectErrorsCount : 2 ,
8497 },
8598 "Map keys valid" : {
8699 val : types.Map {
@@ -93,7 +106,7 @@ func TestKeysAreValidator(t *testing.T) {
93106 keysAreValidators : []tfsdk.AttributeValidator {
94107 stringvalidator .LengthAtLeast (3 ),
95108 },
96- expectError : false ,
109+ expectErrorsCount : 0 ,
97110 },
98111 }
99112
@@ -108,12 +121,8 @@ func TestKeysAreValidator(t *testing.T) {
108121 response := tfsdk.ValidateAttributeResponse {}
109122 KeysAre (test .keysAreValidators ... ).Validate (context .TODO (), request , & response )
110123
111- if ! response .Diagnostics .HasError () && test .expectError {
112- t .Fatal ("expected error, got no error" )
113- }
114-
115- if response .Diagnostics .HasError () && ! test .expectError {
116- t .Fatalf ("got unexpected error: %s" , response .Diagnostics )
124+ if response .Diagnostics .ErrorsCount () != test .expectErrorsCount {
125+ t .Fatalf ("expected %d errors, but got %d: %s" , test .expectErrorsCount , response .Diagnostics .ErrorsCount (), response .Diagnostics )
117126 }
118127 })
119128 }
0 commit comments