@@ -5,53 +5,53 @@ import (
5
5
6
6
"github.com/google/go-cmp/cmp"
7
7
"github.com/hashicorp/terraform-plugin-framework/diag"
8
- "github.com/hashicorp/terraform-plugin-go/tftypes "
8
+ "github.com/hashicorp/terraform-plugin-framework/path "
9
9
)
10
10
11
11
func TestDiagnosticsAddAttributeError (t * testing.T ) {
12
12
t .Parallel ()
13
13
14
14
testCases := map [string ]struct {
15
15
diags diag.Diagnostics
16
- path * tftypes. AttributePath
16
+ path path. Path
17
17
summary string
18
18
detail string
19
19
expected diag.Diagnostics
20
20
}{
21
21
"nil-add" : {
22
22
diags : nil ,
23
- path : tftypes . NewAttributePath (). WithAttributeName ("test" ),
23
+ path : path . RootPath ("test" ),
24
24
summary : "one summary" ,
25
25
detail : "one detail" ,
26
26
expected : diag.Diagnostics {
27
- diag .NewAttributeErrorDiagnostic (tftypes . NewAttributePath (). WithAttributeName ("test" ), "one summary" , "one detail" ),
27
+ diag .NewAttributeErrorDiagnostic (path . RootPath ("test" ), "one summary" , "one detail" ),
28
28
},
29
29
},
30
30
"add" : {
31
31
diags : diag.Diagnostics {
32
- diag .NewAttributeErrorDiagnostic (tftypes . NewAttributePath (). WithAttributeName ("test" ), "one summary" , "one detail" ),
33
- diag .NewAttributeWarningDiagnostic (tftypes . NewAttributePath (). WithAttributeName ("test" ), "two summary" , "two detail" ),
32
+ diag .NewAttributeErrorDiagnostic (path . RootPath ("test" ), "one summary" , "one detail" ),
33
+ diag .NewAttributeWarningDiagnostic (path . RootPath ("test" ), "two summary" , "two detail" ),
34
34
},
35
- path : tftypes . NewAttributePath (). WithAttributeName ("test" ),
35
+ path : path . RootPath ("test" ),
36
36
summary : "three summary" ,
37
37
detail : "three detail" ,
38
38
expected : diag.Diagnostics {
39
- diag .NewAttributeErrorDiagnostic (tftypes . NewAttributePath (). WithAttributeName ("test" ), "one summary" , "one detail" ),
40
- diag .NewAttributeWarningDiagnostic (tftypes . NewAttributePath (). WithAttributeName ("test" ), "two summary" , "two detail" ),
41
- diag .NewAttributeErrorDiagnostic (tftypes . NewAttributePath (). WithAttributeName ("test" ), "three summary" , "three detail" ),
39
+ diag .NewAttributeErrorDiagnostic (path . RootPath ("test" ), "one summary" , "one detail" ),
40
+ diag .NewAttributeWarningDiagnostic (path . RootPath ("test" ), "two summary" , "two detail" ),
41
+ diag .NewAttributeErrorDiagnostic (path . RootPath ("test" ), "three summary" , "three detail" ),
42
42
},
43
43
},
44
44
"duplicate" : {
45
45
diags : diag.Diagnostics {
46
- diag .NewAttributeErrorDiagnostic (tftypes . NewAttributePath (). WithAttributeName ("test" ), "one summary" , "one detail" ),
47
- diag .NewAttributeWarningDiagnostic (tftypes . NewAttributePath (). WithAttributeName ("test" ), "two summary" , "two detail" ),
46
+ diag .NewAttributeErrorDiagnostic (path . RootPath ("test" ), "one summary" , "one detail" ),
47
+ diag .NewAttributeWarningDiagnostic (path . RootPath ("test" ), "two summary" , "two detail" ),
48
48
},
49
- path : tftypes . NewAttributePath (). WithAttributeName ("test" ),
49
+ path : path . RootPath ("test" ),
50
50
summary : "one summary" ,
51
51
detail : "one detail" ,
52
52
expected : diag.Diagnostics {
53
- diag .NewAttributeErrorDiagnostic (tftypes . NewAttributePath (). WithAttributeName ("test" ), "one summary" , "one detail" ),
54
- diag .NewAttributeWarningDiagnostic (tftypes . NewAttributePath (). WithAttributeName ("test" ), "two summary" , "two detail" ),
53
+ diag .NewAttributeErrorDiagnostic (path . RootPath ("test" ), "one summary" , "one detail" ),
54
+ diag .NewAttributeWarningDiagnostic (path . RootPath ("test" ), "two summary" , "two detail" ),
55
55
},
56
56
},
57
57
}
@@ -75,45 +75,45 @@ func TestDiagnosticsAddAttributeWarning(t *testing.T) {
75
75
76
76
testCases := map [string ]struct {
77
77
diags diag.Diagnostics
78
- path * tftypes. AttributePath
78
+ path path. Path
79
79
summary string
80
80
detail string
81
81
expected diag.Diagnostics
82
82
}{
83
83
"nil-add" : {
84
84
diags : nil ,
85
- path : tftypes . NewAttributePath (). WithAttributeName ("test" ),
85
+ path : path . RootPath ("test" ),
86
86
summary : "one summary" ,
87
87
detail : "one detail" ,
88
88
expected : diag.Diagnostics {
89
- diag .NewAttributeWarningDiagnostic (tftypes . NewAttributePath (). WithAttributeName ("test" ), "one summary" , "one detail" ),
89
+ diag .NewAttributeWarningDiagnostic (path . RootPath ("test" ), "one summary" , "one detail" ),
90
90
},
91
91
},
92
92
"add" : {
93
93
diags : diag.Diagnostics {
94
- diag .NewAttributeErrorDiagnostic (tftypes . NewAttributePath (). WithAttributeName ("test" ), "one summary" , "one detail" ),
95
- diag .NewAttributeWarningDiagnostic (tftypes . NewAttributePath (). WithAttributeName ("test" ), "two summary" , "two detail" ),
94
+ diag .NewAttributeErrorDiagnostic (path . RootPath ("test" ), "one summary" , "one detail" ),
95
+ diag .NewAttributeWarningDiagnostic (path . RootPath ("test" ), "two summary" , "two detail" ),
96
96
},
97
- path : tftypes . NewAttributePath (). WithAttributeName ("test" ),
97
+ path : path . RootPath ("test" ),
98
98
summary : "three summary" ,
99
99
detail : "three detail" ,
100
100
expected : diag.Diagnostics {
101
- diag .NewAttributeErrorDiagnostic (tftypes . NewAttributePath (). WithAttributeName ("test" ), "one summary" , "one detail" ),
102
- diag .NewAttributeWarningDiagnostic (tftypes . NewAttributePath (). WithAttributeName ("test" ), "two summary" , "two detail" ),
103
- diag .NewAttributeWarningDiagnostic (tftypes . NewAttributePath (). WithAttributeName ("test" ), "three summary" , "three detail" ),
101
+ diag .NewAttributeErrorDiagnostic (path . RootPath ("test" ), "one summary" , "one detail" ),
102
+ diag .NewAttributeWarningDiagnostic (path . RootPath ("test" ), "two summary" , "two detail" ),
103
+ diag .NewAttributeWarningDiagnostic (path . RootPath ("test" ), "three summary" , "three detail" ),
104
104
},
105
105
},
106
106
"duplicate" : {
107
107
diags : diag.Diagnostics {
108
- diag .NewAttributeErrorDiagnostic (tftypes . NewAttributePath (). WithAttributeName ("test" ), "one summary" , "one detail" ),
109
- diag .NewAttributeWarningDiagnostic (tftypes . NewAttributePath (). WithAttributeName ("test" ), "two summary" , "two detail" ),
108
+ diag .NewAttributeErrorDiagnostic (path . RootPath ("test" ), "one summary" , "one detail" ),
109
+ diag .NewAttributeWarningDiagnostic (path . RootPath ("test" ), "two summary" , "two detail" ),
110
110
},
111
- path : tftypes . NewAttributePath (). WithAttributeName ("test" ),
111
+ path : path . RootPath ("test" ),
112
112
summary : "two summary" ,
113
113
detail : "two detail" ,
114
114
expected : diag.Diagnostics {
115
- diag .NewAttributeErrorDiagnostic (tftypes . NewAttributePath (). WithAttributeName ("test" ), "one summary" , "one detail" ),
116
- diag .NewAttributeWarningDiagnostic (tftypes . NewAttributePath (). WithAttributeName ("test" ), "two summary" , "two detail" ),
115
+ diag .NewAttributeErrorDiagnostic (path . RootPath ("test" ), "one summary" , "one detail" ),
116
+ diag .NewAttributeWarningDiagnostic (path . RootPath ("test" ), "two summary" , "two detail" ),
117
117
},
118
118
},
119
119
}
@@ -285,16 +285,16 @@ func TestDiagnosticsAppend(t *testing.T) {
285
285
},
286
286
"append-less-specific" : {
287
287
diags : diag.Diagnostics {
288
- diag .NewAttributeErrorDiagnostic (tftypes . NewAttributePath (). WithAttributeName ("error" ), "one summary" , "one detail" ),
289
- diag .NewAttributeWarningDiagnostic (tftypes . NewAttributePath (). WithAttributeName ("warning" ), "two summary" , "two detail" ),
288
+ diag .NewAttributeErrorDiagnostic (path . RootPath ("error" ), "one summary" , "one detail" ),
289
+ diag .NewAttributeWarningDiagnostic (path . RootPath ("warning" ), "two summary" , "two detail" ),
290
290
},
291
291
in : diag.Diagnostics {
292
292
diag .NewErrorDiagnostic ("one summary" , "one detail" ),
293
293
diag .NewWarningDiagnostic ("two summary" , "two detail" ),
294
294
},
295
295
expected : diag.Diagnostics {
296
- diag .NewAttributeErrorDiagnostic (tftypes . NewAttributePath (). WithAttributeName ("error" ), "one summary" , "one detail" ),
297
- diag .NewAttributeWarningDiagnostic (tftypes . NewAttributePath (). WithAttributeName ("warning" ), "two summary" , "two detail" ),
296
+ diag .NewAttributeErrorDiagnostic (path . RootPath ("error" ), "one summary" , "one detail" ),
297
+ diag .NewAttributeWarningDiagnostic (path . RootPath ("warning" ), "two summary" , "two detail" ),
298
298
diag .NewErrorDiagnostic ("one summary" , "one detail" ),
299
299
diag .NewWarningDiagnostic ("two summary" , "two detail" ),
300
300
},
@@ -305,14 +305,14 @@ func TestDiagnosticsAppend(t *testing.T) {
305
305
diag .NewWarningDiagnostic ("two summary" , "two detail" ),
306
306
},
307
307
in : diag.Diagnostics {
308
- diag .NewAttributeErrorDiagnostic (tftypes . NewAttributePath (). WithAttributeName ("error" ), "one summary" , "one detail" ),
309
- diag .NewAttributeWarningDiagnostic (tftypes . NewAttributePath (). WithAttributeName ("warning" ), "two summary" , "two detail" ),
308
+ diag .NewAttributeErrorDiagnostic (path . RootPath ("error" ), "one summary" , "one detail" ),
309
+ diag .NewAttributeWarningDiagnostic (path . RootPath ("warning" ), "two summary" , "two detail" ),
310
310
},
311
311
expected : diag.Diagnostics {
312
312
diag .NewErrorDiagnostic ("one summary" , "one detail" ),
313
313
diag .NewWarningDiagnostic ("two summary" , "two detail" ),
314
- diag .NewAttributeErrorDiagnostic (tftypes . NewAttributePath (). WithAttributeName ("error" ), "one summary" , "one detail" ),
315
- diag .NewAttributeWarningDiagnostic (tftypes . NewAttributePath (). WithAttributeName ("warning" ), "two summary" , "two detail" ),
314
+ diag .NewAttributeErrorDiagnostic (path . RootPath ("error" ), "one summary" , "one detail" ),
315
+ diag .NewAttributeWarningDiagnostic (path . RootPath ("warning" ), "two summary" , "two detail" ),
316
316
},
317
317
},
318
318
"empty-diagnostics" : {
@@ -388,10 +388,10 @@ func TestDiagnosticsContains(t *testing.T) {
388
388
},
389
389
"matching-attribute-path" : {
390
390
diags : diag.Diagnostics {
391
- diag .NewAttributeErrorDiagnostic (tftypes . NewAttributePath (). WithAttributeName ("error" ), "one summary" , "one detail" ),
392
- diag .NewAttributeWarningDiagnostic (tftypes . NewAttributePath (). WithAttributeName ("warning" ), "two summary" , "two detail" ),
391
+ diag .NewAttributeErrorDiagnostic (path . RootPath ("error" ), "one summary" , "one detail" ),
392
+ diag .NewAttributeWarningDiagnostic (path . RootPath ("warning" ), "two summary" , "two detail" ),
393
393
},
394
- in : diag .NewAttributeWarningDiagnostic (tftypes . NewAttributePath (). WithAttributeName ("warning" ), "two summary" , "two detail" ),
394
+ in : diag .NewAttributeWarningDiagnostic (path . RootPath ("warning" ), "two summary" , "two detail" ),
395
395
expected : true ,
396
396
},
397
397
"nil-diagnostics" : {
@@ -409,10 +409,10 @@ func TestDiagnosticsContains(t *testing.T) {
409
409
},
410
410
"different-attribute-path" : {
411
411
diags : diag.Diagnostics {
412
- diag .NewAttributeErrorDiagnostic (tftypes . NewAttributePath (). WithAttributeName ("error" ), "one summary" , "one detail" ),
413
- diag .NewAttributeWarningDiagnostic (tftypes . NewAttributePath (). WithAttributeName ("warning" ), "two summary" , "two detail" ),
412
+ diag .NewAttributeErrorDiagnostic (path . RootPath ("error" ), "one summary" , "one detail" ),
413
+ diag .NewAttributeWarningDiagnostic (path . RootPath ("warning" ), "two summary" , "two detail" ),
414
414
},
415
- in : diag .NewAttributeWarningDiagnostic (tftypes . NewAttributePath (). WithAttributeName ("different" ), "two summary" , "two detail" ),
415
+ in : diag .NewAttributeWarningDiagnostic (path . RootPath ("different" ), "two summary" , "two detail" ),
416
416
expected : false ,
417
417
},
418
418
"different-detail" : {
@@ -441,8 +441,8 @@ func TestDiagnosticsContains(t *testing.T) {
441
441
},
442
442
"different-type-less-specific" : {
443
443
diags : diag.Diagnostics {
444
- diag .NewAttributeErrorDiagnostic (tftypes . NewAttributePath (). WithAttributeName ("error" ), "one summary" , "one detail" ),
445
- diag .NewAttributeWarningDiagnostic (tftypes . NewAttributePath (). WithAttributeName ("warning" ), "two summary" , "two detail" ),
444
+ diag .NewAttributeErrorDiagnostic (path . RootPath ("error" ), "one summary" , "one detail" ),
445
+ diag .NewAttributeWarningDiagnostic (path . RootPath ("warning" ), "two summary" , "two detail" ),
446
446
},
447
447
in : diag .NewWarningDiagnostic ("two summary" , "two detail" ),
448
448
expected : false ,
@@ -452,7 +452,7 @@ func TestDiagnosticsContains(t *testing.T) {
452
452
diag .NewErrorDiagnostic ("one summary" , "one detail" ),
453
453
diag .NewWarningDiagnostic ("two summary" , "two detail" ),
454
454
},
455
- in : diag .NewAttributeWarningDiagnostic (tftypes . NewAttributePath (). WithAttributeName ("warning" ), "two summary" , "two detail" ),
455
+ in : diag .NewAttributeWarningDiagnostic (path . RootPath ("warning" ), "two summary" , "two detail" ),
456
456
expected : false ,
457
457
},
458
458
}
@@ -487,8 +487,8 @@ func TestDiagnosticsHasError(t *testing.T) {
487
487
},
488
488
"matching-attribute-path" : {
489
489
diags : diag.Diagnostics {
490
- diag .NewAttributeErrorDiagnostic (tftypes . NewAttributePath (). WithAttributeName ("error" ), "one summary" , "one detail" ),
491
- diag .NewAttributeWarningDiagnostic (tftypes . NewAttributePath (). WithAttributeName ("warning" ), "two summary" , "two detail" ),
490
+ diag .NewAttributeErrorDiagnostic (path . RootPath ("error" ), "one summary" , "one detail" ),
491
+ diag .NewAttributeWarningDiagnostic (path . RootPath ("warning" ), "two summary" , "two detail" ),
492
492
},
493
493
expected : true ,
494
494
},
0 commit comments