@@ -86,3 +86,106 @@ func TestValidateTransformations_DebeziumUnwrap(t *testing.T) {
8686 }
8787 })
8888}
89+
90+ func TestValidateTransformations_ReplaceField (t * testing.T ) {
91+ baseSpec := DataFlowSpec {
92+ Source : SourceSpec {
93+ Type : "kafka" ,
94+ Config : mustRawConfigForValidation (KafkaSourceSpec {Brokers : []string {"broker:9092" }, Topic : "src" }),
95+ },
96+ Sink : SinkSpec {
97+ Type : "kafka" ,
98+ Config : mustRawConfigForValidation (KafkaSinkSpec {Brokers : []string {"broker:9092" }, Topic : "dst" }),
99+ },
100+ }
101+
102+ t .Run ("valid renames" , func (t * testing.T ) {
103+ spec := baseSpec
104+ spec .Transformations = []TransformationSpec {{
105+ Type : "replaceField" ,
106+ Config : mustRawConfigForValidation (ReplaceFieldTransformation {
107+ Renames : []string {"old:new" , "a.b:c" },
108+ }),
109+ }}
110+ errs := ValidateDataFlowSpec (& spec )
111+ if len (errs ) != 0 {
112+ t .Fatalf ("expected no validation errors, got %v" , errs )
113+ }
114+ })
115+
116+ t .Run ("valid include" , func (t * testing.T ) {
117+ spec := baseSpec
118+ spec .Transformations = []TransformationSpec {{
119+ Type : "replaceField" ,
120+ Config : mustRawConfigForValidation (ReplaceFieldTransformation {
121+ Include : []string {"id" , "user.name" },
122+ }),
123+ }}
124+ errs := ValidateDataFlowSpec (& spec )
125+ if len (errs ) != 0 {
126+ t .Fatalf ("expected no validation errors, got %v" , errs )
127+ }
128+ })
129+
130+ t .Run ("missing config" , func (t * testing.T ) {
131+ spec := baseSpec
132+ spec .Transformations = []TransformationSpec {{Type : "replaceField" }}
133+ errs := ValidateDataFlowSpec (& spec )
134+ if len (errs ) == 0 {
135+ t .Fatal ("expected validation error for missing config" )
136+ }
137+ if ! strings .Contains (errs .ToAggregate ().Error (), "replaceField transformation configuration is required" ) {
138+ t .Fatalf ("unexpected error: %v" , errs .ToAggregate ())
139+ }
140+ })
141+
142+ t .Run ("empty config" , func (t * testing.T ) {
143+ spec := baseSpec
144+ spec .Transformations = []TransformationSpec {{
145+ Type : "replaceField" ,
146+ Config : mustRawConfigForValidation (ReplaceFieldTransformation {}),
147+ }}
148+ errs := ValidateDataFlowSpec (& spec )
149+ if len (errs ) == 0 {
150+ t .Fatal ("expected validation error for empty replaceField config" )
151+ }
152+ if ! strings .Contains (errs .ToAggregate ().Error (), "at least one of renames, include, or exclude is required" ) {
153+ t .Fatalf ("unexpected error: %v" , errs .ToAggregate ())
154+ }
155+ })
156+
157+ t .Run ("include and exclude mutually exclusive" , func (t * testing.T ) {
158+ spec := baseSpec
159+ spec .Transformations = []TransformationSpec {{
160+ Type : "replaceField" ,
161+ Config : mustRawConfigForValidation (ReplaceFieldTransformation {
162+ Include : []string {"a" },
163+ Exclude : []string {"b" },
164+ }),
165+ }}
166+ errs := ValidateDataFlowSpec (& spec )
167+ if len (errs ) == 0 {
168+ t .Fatal ("expected validation error for include+exclude" )
169+ }
170+ if ! strings .Contains (errs .ToAggregate ().Error (), "mutually exclusive" ) {
171+ t .Fatalf ("unexpected error: %v" , errs .ToAggregate ())
172+ }
173+ })
174+
175+ t .Run ("invalid rename format" , func (t * testing.T ) {
176+ spec := baseSpec
177+ spec .Transformations = []TransformationSpec {{
178+ Type : "replaceField" ,
179+ Config : mustRawConfigForValidation (ReplaceFieldTransformation {
180+ Renames : []string {"bad-format" },
181+ }),
182+ }}
183+ errs := ValidateDataFlowSpec (& spec )
184+ if len (errs ) == 0 {
185+ t .Fatal ("expected validation error for invalid rename" )
186+ }
187+ if ! strings .Contains (errs .ToAggregate ().Error (), "oldPath:newPath" ) {
188+ t .Fatalf ("unexpected error: %v" , errs .ToAggregate ())
189+ }
190+ })
191+ }
0 commit comments