@@ -4,24 +4,139 @@ import (
4
4
"context"
5
5
"testing"
6
6
7
- "github.com/databricks/terraform-provider-databricks/internal/ service/sharing_tf "
8
- "github.com/hashicorp /terraform-plugin-framework/types "
7
+ "github.com/databricks/databricks-sdk-go/ service/sharing "
8
+ "github.com/databricks /terraform-provider-databricks/internal/providers/pluginfw/converters "
9
9
"github.com/stretchr/testify/assert"
10
10
)
11
11
12
12
func TestShareSyncEffectiveFields (t * testing.T ) {
13
13
shareName := "test-share-name"
14
+ ctx := context .Background ()
14
15
shares := ShareResource {}
15
- plan := ShareInfoExtended {
16
- ShareInfo_SdkV2 : sharing_tf.ShareInfo_SdkV2 {
17
- Name : types .StringValue (shareName ),
16
+
17
+ tests := []struct {
18
+ name string
19
+ planGoSDK sharing.ShareInfo
20
+ stateGoSDK sharing.ShareInfo
21
+ }{
22
+ {
23
+ name : "plan with less objects" ,
24
+ planGoSDK : sharing.ShareInfo {
25
+ Name : shareName ,
26
+ Objects : []sharing.SharedDataObject {
27
+ {
28
+ Name : "obj-1" ,
29
+ Partitions : []sharing.Partition {
30
+ {Values : []sharing.PartitionValue {{Value : "part-1" }}},
31
+ },
32
+ },
33
+ {
34
+ Name : "obj-3" ,
35
+ Partitions : []sharing.Partition {
36
+ {Values : []sharing.PartitionValue {{Value : "part-3" }}},
37
+ },
38
+ },
39
+ },
40
+ },
41
+ stateGoSDK : sharing.ShareInfo {
42
+ Name : shareName ,
43
+ Objects : []sharing.SharedDataObject {
44
+ {
45
+ Name : "obj-1" ,
46
+ Partitions : []sharing.Partition {
47
+ {Values : []sharing.PartitionValue {{Value : "part-1" }}},
48
+ },
49
+ },
50
+ {
51
+ Name : "obj-2" ,
52
+ Partitions : []sharing.Partition {
53
+ {Values : []sharing.PartitionValue {{Value : "part-2" }}},
54
+ },
55
+ },
56
+ {
57
+ Name : "obj-3" ,
58
+ Partitions : []sharing.Partition {
59
+ {Values : []sharing.PartitionValue {{Value : "part-3" }}},
60
+ },
61
+ },
62
+ },
63
+ },
18
64
},
19
- }
20
- state := ShareInfoExtended {
21
- ShareInfo_SdkV2 : sharing_tf.ShareInfo_SdkV2 {
22
- Name : types .StringValue (shareName ),
65
+ {
66
+ name : "plan with more objects" ,
67
+ planGoSDK : sharing.ShareInfo {
68
+ Name : shareName ,
69
+ Objects : []sharing.SharedDataObject {
70
+ {
71
+ Name : "obj-1" ,
72
+ Partitions : []sharing.Partition {
73
+ {Values : []sharing.PartitionValue {{Value : "part-1" }}},
74
+ },
75
+ },
76
+ {
77
+ Name : "obj-2" ,
78
+ Partitions : []sharing.Partition {
79
+ {Values : []sharing.PartitionValue {{Value : "part-2" }}},
80
+ },
81
+ },
82
+ {
83
+ Name : "obj-3" ,
84
+ Partitions : []sharing.Partition {
85
+ {Values : []sharing.PartitionValue {{Value : "part-3" }}},
86
+ },
87
+ },
88
+ },
89
+ },
90
+ stateGoSDK : sharing.ShareInfo {
91
+ Name : shareName ,
92
+ Objects : []sharing.SharedDataObject {
93
+ {
94
+ Name : "obj-1" ,
95
+ Partitions : []sharing.Partition {
96
+ {Values : []sharing.PartitionValue {{Value : "part-1" }}},
97
+ },
98
+ },
99
+ {
100
+ Name : "obj-3" ,
101
+ Partitions : []sharing.Partition {
102
+ {Values : []sharing.PartitionValue {{Value : "part-3" }}},
103
+ },
104
+ },
105
+ },
106
+ },
23
107
},
108
+ {
109
+ name : "empty plan" ,
110
+ planGoSDK : sharing.ShareInfo {
111
+ Name : shareName ,
112
+ Objects : []sharing.SharedDataObject {},
113
+ },
114
+ stateGoSDK : sharing.ShareInfo {
115
+ Name : shareName ,
116
+ Objects : []sharing.SharedDataObject {
117
+ {
118
+ Name : "obj-1" ,
119
+ Partitions : []sharing.Partition {
120
+ {Values : []sharing.PartitionValue {{Value : "part-1" }}},
121
+ },
122
+ },
123
+ },
124
+ },
125
+ },
126
+ }
127
+
128
+ for _ , tt := range tests {
129
+ t .Run (tt .name , func (t * testing.T ) {
130
+ var planTFSDK ShareInfoExtended
131
+ diagnostics := converters .GoSdkToTfSdkStruct (ctx , tt .planGoSDK , & planTFSDK )
132
+ assert .False (t , diagnostics .HasError ())
133
+
134
+ var stateTFSDK ShareInfoExtended
135
+ diagnostics = converters .GoSdkToTfSdkStruct (ctx , tt .stateGoSDK , & stateTFSDK )
136
+ assert .False (t , diagnostics .HasError ())
137
+
138
+ _ , diagnostics = shares .syncEffectiveFields (ctx , planTFSDK , stateTFSDK , effectiveFieldsActionRead {})
139
+ assert .False (t , diagnostics .HasError ())
140
+ })
24
141
}
25
- _ , diagnostics := shares .syncEffectiveFields (context .Background (), plan , state , effectiveFieldsActionRead {})
26
- assert .False (t , diagnostics .HasError ())
27
142
}
0 commit comments