-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconvert_test.go
137 lines (130 loc) · 2.94 KB
/
convert_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
package tfconv_test
import (
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"k8s.io/apimachinery/pkg/api/resource"
)
type likeAString string
type TestObject struct {
Str string `json:"str"`
Alias StrAlias `json:"alias"`
Int int `json:"int"`
Float float64 `json:"float,omitempty"`
Bool bool `json:"bool"`
Slice []T `json:"slice"`
StringSlice []string `json:"stringSlice"`
Map map[string]int `json:"map"`
MapConvert map[likeAString]string `json:"mapConvert"`
Struct *T `json:"struct"`
Q resource.Quantity `json:"q"`
QPtr *resource.Quantity `json:"qPtr"`
}
type T struct {
A string `json:"a"`
B *int `json:"b"`
C *int `json:"c"`
}
type StrAlias string
func testObjectSchema() map[string]*schema.Schema {
return map[string]*schema.Schema{
"alias": {
Type: schema.TypeString,
Optional: true,
},
"bool": {
Type: schema.TypeBool,
Optional: true,
},
"float": {
Type: schema.TypeFloat,
Optional: true,
},
"int": {
Type: schema.TypeInt,
Optional: true,
},
"map": {
Type: schema.TypeMap,
Optional: true,
Elem: &schema.Schema{Type: schema.TypeInt},
},
"map_convert": {
Type: schema.TypeMap,
Optional: true,
Elem: &schema.Schema{Type: schema.TypeString},
},
"q": {
Type: schema.TypeString,
Optional: true,
},
"q_ptr": {
Type: schema.TypeList,
MaxItems: 1,
Optional: true,
Elem: &schema.Resource{Schema: map[string]*schema.Schema{
"value": {
Type: schema.TypeString,
Required: true,
},
}},
},
"slice": {
Type: schema.TypeList,
Optional: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"a": {
Type: schema.TypeString,
Optional: true,
},
},
},
},
"string_slice": {
Type: schema.TypeList,
Optional: true,
Elem: &schema.Schema{Type: schema.TypeString},
},
"str": {
Type: schema.TypeString,
Optional: true,
},
"struct": {
Type: schema.TypeList,
Optional: true,
MaxItems: 1,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"a": {
Type: schema.TypeString,
Optional: true,
},
"b": {
Type: schema.TypeList,
MaxItems: 1,
Optional: true,
Elem: &schema.Resource{Schema: map[string]*schema.Schema{
"value": {
Type: schema.TypeInt,
Required: true,
},
}},
},
"c": {
Type: schema.TypeList,
MaxItems: 1,
Optional: true,
Elem: &schema.Resource{Schema: map[string]*schema.Schema{
"value": {
Type: schema.TypeInt,
Required: true,
},
}},
},
},
},
},
}
}
func ptrOf[T any](v T) *T {
return &v
}