@@ -37,6 +37,23 @@ func TestValidationMapKeyLenBetween(t *testing.T) {
3737 },
3838 },
3939 },
40+ "TooLongAndTooShort" : {
41+ Value : map [string ]interface {}{
42+ "UVWXYZ" : "123456" ,
43+ "ABC" : "123" ,
44+ "U" : "1" ,
45+ },
46+ ExpectedDiags : diag.Diagnostics {
47+ {
48+ Severity : diag .Error ,
49+ AttributePath : append (cty.Path {}, cty.IndexStep {Key : cty .StringVal ("U" )}),
50+ },
51+ {
52+ Severity : diag .Error ,
53+ AttributePath : append (cty.Path {}, cty.IndexStep {Key : cty .StringVal ("UVWXYZ" )}),
54+ },
55+ },
56+ },
4057 "AllGood" : {
4158 Value : map [string ]interface {}{
4259 "AB" : "12" ,
@@ -52,17 +69,7 @@ func TestValidationMapKeyLenBetween(t *testing.T) {
5269 t .Run (tn , func (t * testing.T ) {
5370 diags := fn (tc .Value , cty.Path {})
5471
55- if len (diags ) != len (tc .ExpectedDiags ) {
56- t .Fatalf ("%s: wrong number of diags, expected %d, got %d" , tn , len (tc .ExpectedDiags ), len (diags ))
57- }
58- for j := range diags {
59- if diags [j ].Severity != tc .ExpectedDiags [j ].Severity {
60- t .Fatalf ("%s: expected severity %v, got %v" , tn , tc .ExpectedDiags [j ].Severity , diags [j ].Severity )
61- }
62- if ! diags [j ].AttributePath .Equals (tc .ExpectedDiags [j ].AttributePath ) {
63- t .Fatalf ("%s: attribute paths do not match expected: %v, got %v" , tn , tc .ExpectedDiags [j ].AttributePath , diags [j ].AttributePath )
64- }
65- }
72+ checkDiagnostics (t , tn , diags , tc .ExpectedDiags )
6673 })
6774 }
6875}
@@ -207,3 +214,17 @@ func TestValidationValueKeyMatch(t *testing.T) {
207214 })
208215 }
209216}
217+
218+ func checkDiagnostics (t * testing.T , tn string , got , expected diag.Diagnostics ) {
219+ if len (got ) != len (expected ) {
220+ t .Fatalf ("%s: wrong number of diags, expected %d, got %d" , tn , len (expected ), len (got ))
221+ }
222+ for j := range got {
223+ if got [j ].Severity != expected [j ].Severity {
224+ t .Fatalf ("%s: expected severity %v, got %v" , tn , expected [j ].Severity , got [j ].Severity )
225+ }
226+ if ! got [j ].AttributePath .Equals (expected [j ].AttributePath ) {
227+ t .Fatalf ("%s: attribute paths do not match expected: %v, got %v" , tn , expected [j ].AttributePath , got [j ].AttributePath )
228+ }
229+ }
230+ }
0 commit comments