@@ -249,6 +249,113 @@ func TestApplyPath(t *testing.T) {
249
249
cty .NilVal ,
250
250
`Attempt to get attribute from null value: This value is null, so it does not have any attributes.` ,
251
251
},
252
+
253
+ // Marks should be retained during index and getattr ops, even when
254
+ // types and values are unknown. This reflects the same behavior when
255
+ // using cty to directly call GetAttr and Index methods.
256
+ {
257
+ cty .DynamicVal .Mark ("marked" ),
258
+ (cty .Path )(nil ).GetAttr ("foo" ),
259
+ cty .DynamicVal .Mark ("marked" ),
260
+ `` ,
261
+ },
262
+ {
263
+ cty .ObjectVal (map [string ]cty.Value {
264
+ "foo" : cty .StringVal ("should be marked" ),
265
+ }).Mark ("marked" ),
266
+ (cty .Path )(nil ).GetAttr ("foo" ),
267
+ cty .StringVal ("should be marked" ).Mark ("marked" ),
268
+ `` ,
269
+ },
270
+ {
271
+ cty .UnknownVal (cty .Object (map [string ]cty.Type {
272
+ "foo" : cty .DynamicPseudoType ,
273
+ })).Mark ("marked" ),
274
+ (cty .Path )(nil ).GetAttr ("foo" ),
275
+ cty .DynamicVal .Mark ("marked" ),
276
+ `` ,
277
+ },
278
+ {
279
+ cty .DynamicVal .Mark ("marked" ),
280
+ (cty .Path )(nil ).Index (cty .StringVal ("foo" )),
281
+ cty .DynamicVal .Mark ("marked" ),
282
+ `` ,
283
+ },
284
+ {
285
+ cty .ObjectVal (map [string ]cty.Value {
286
+ "foo" : cty .StringVal ("should be marked" ),
287
+ }).Mark ("marked" ),
288
+ (cty .Path )(nil ).Index (cty .StringVal ("foo" )),
289
+ cty .StringVal ("should be marked" ).Mark ("marked" ),
290
+ `` ,
291
+ },
292
+ {
293
+ cty .UnknownVal (cty .Object (map [string ]cty.Type {
294
+ "foo" : cty .DynamicPseudoType ,
295
+ })).Mark ("marked" ),
296
+ (cty .Path )(nil ).Index (cty .StringVal ("foo" )),
297
+ cty .DynamicVal .Mark ("marked" ),
298
+ `` ,
299
+ },
300
+ {
301
+ cty .DynamicVal .Mark ("marked" ),
302
+ (cty .Path )(nil ).Index (cty .NumberIntVal (0 )),
303
+ cty .DynamicVal .Mark ("marked" ),
304
+ `` ,
305
+ },
306
+ {
307
+ cty .ListVal ([]cty.Value {cty .StringVal ("should be marked" )}).Mark ("marked" ),
308
+ (cty .Path )(nil ).Index (cty .NumberIntVal (0 )),
309
+ cty .StringVal ("should be marked" ).Mark ("marked" ),
310
+ `` ,
311
+ },
312
+ {
313
+ cty .UnknownVal (cty .List (cty .String )).Mark ("marked" ),
314
+ (cty .Path )(nil ).Index (cty .NumberIntVal (0 )),
315
+ cty .UnknownVal (cty .String ).Mark ("marked" ),
316
+ `` ,
317
+ },
318
+
319
+ {
320
+ cty .DynamicVal .Mark ("marked" ),
321
+ (cty .Path )(nil ).Index (cty .UnknownVal (cty .String )),
322
+ cty .DynamicVal .Mark ("marked" ),
323
+ `` ,
324
+ },
325
+ {
326
+ cty .ObjectVal (map [string ]cty.Value {
327
+ "foo" : cty .StringVal ("should be marked" ),
328
+ }).Mark ("marked" ),
329
+ (cty .Path )(nil ).Index (cty .UnknownVal (cty .String )),
330
+ cty .DynamicVal .Mark ("marked" ),
331
+ `` ,
332
+ },
333
+ {
334
+ cty .UnknownVal (cty .Object (map [string ]cty.Type {
335
+ "foo" : cty .DynamicPseudoType ,
336
+ })).Mark ("marked" ),
337
+ (cty .Path )(nil ).Index (cty .UnknownVal (cty .String )),
338
+ cty .DynamicVal .Mark ("marked" ),
339
+ `` ,
340
+ },
341
+ {
342
+ cty .DynamicVal .Mark ("marked" ),
343
+ (cty .Path )(nil ).Index (cty .UnknownVal (cty .Number )),
344
+ cty .DynamicVal .Mark ("marked" ),
345
+ `` ,
346
+ },
347
+ {
348
+ cty .ListVal ([]cty.Value {cty .StringVal ("should be marked" )}).Mark ("marked" ),
349
+ (cty .Path )(nil ).Index (cty .UnknownVal (cty .Number )),
350
+ cty .UnknownVal (cty .String ).Mark ("marked" ),
351
+ `` ,
352
+ },
353
+ {
354
+ cty .UnknownVal (cty .List (cty .String )).Mark ("marked" ),
355
+ (cty .Path )(nil ).Index (cty .UnknownVal (cty .Number )),
356
+ cty .UnknownVal (cty .String ).Mark ("marked" ),
357
+ `` ,
358
+ },
252
359
}
253
360
254
361
for _ , test := range tests {
@@ -257,7 +364,7 @@ func TestApplyPath(t *testing.T) {
257
364
t .Logf ("testing ApplyPath\n start: %#v\n path: %#v" , test .Start , test .Path )
258
365
259
366
for _ , diag := range diags {
260
- t .Logf (diag .Error ())
367
+ t .Log (diag .Error ())
261
368
}
262
369
263
370
if test .WantErr != "" {
0 commit comments