@@ -6,9 +6,11 @@ import (
66 "reflect"
77 "testing"
88
9+ "github.com/google/go-cmp/cmp"
910 "github.com/hashicorp/terraform-plugin-framework/diag"
1011 sdkClients "github.com/stackitcloud/stackit-sdk-go/core/clients"
1112 "github.com/stackitcloud/stackit-sdk-go/core/config"
13+ utils2 "github.com/stackitcloud/stackit-sdk-go/core/utils"
1214 "github.com/stackitcloud/stackit-sdk-go/services/sfs"
1315 "github.com/stackitcloud/terraform-provider-stackit/stackit/internal/core"
1416 "github.com/stackitcloud/terraform-provider-stackit/stackit/internal/utils"
@@ -91,3 +93,50 @@ func TestConfigureClient(t *testing.T) {
9193 })
9294 }
9395}
96+
97+ func TestDescribeValidationError (t * testing.T ) {
98+ tests := []struct {
99+ name string
100+ err sfs.ValidationError
101+ want string
102+ }{
103+ {
104+ name : "just title" ,
105+ err : sfs.ValidationError {
106+ Title : utils2 .Ptr ("nice title" ),
107+ },
108+ want : `nice title
109+ ` ,
110+ },
111+ {
112+ name : "with fields" ,
113+ err : sfs.ValidationError {
114+ Title : utils2 .Ptr ("nice title" ),
115+ Fields : & []sfs.ValidationErrorField {
116+ {
117+ Field : utils2 .Ptr ("field-a" ),
118+ Reason : utils2 .Ptr ("reason-a" ),
119+ },
120+ {
121+ Reason : utils2 .Ptr ("reason-b" ),
122+ },
123+ {
124+ Field : utils2 .Ptr ("field-c" ),
125+ },
126+ },
127+ },
128+ want : `nice title
129+
130+ Field: field-a | Reason: reason-a
131+ Field: | Reason: reason-b
132+ Field: field-c | Reason: ` ,
133+ },
134+ }
135+
136+ for _ , tt := range tests {
137+ got := DescribeValidationError (tt .err )
138+ if d := cmp .Diff (got , tt .want ); d != "" {
139+ t .Errorf ("DescribeValidationError() = got diff: %s" , d )
140+ }
141+ }
142+ }
0 commit comments