generated from layer5io/layer5-repo-template
-
Notifications
You must be signed in to change notification settings - Fork 121
/
Copy pathgenerator_test.go
162 lines (156 loc) · 4.86 KB
/
generator_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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
package component
import (
"reflect"
"testing"
"github.com/layer5io/meshkit/models/meshmodel/core/v1alpha1"
)
var istioCrd = `
apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
annotations:
"helm.sh/resource-policy": keep
labels:
app: istio-pilot
chart: istio
heritage: Tiller
release: istio
name: wasmplugins.extensions.istio.io
spec:
group: extensions.istio.io
names:
categories:
- istio-io
- extensions-istio-io
kind: WasmPlugin
listKind: WasmPluginList
plural: wasmplugins
singular: wasmplugin
scope: Namespaced
versions:
- additionalPrinterColumns:
- description: 'CreationTimestamp is a timestamp representing the server time
when this object was created. It is not guaranteed to be set in happens-before
order across separate operations. Clients may not set this value. It is represented
in RFC3339 form and is in UTC. Populated by the system. Read-only. Null for
lists. More info: https://git.k8s.io/community/contributors/devel/api-conventions.md#metadata'
jsonPath: .metadata.creationTimestamp
name: Age
type: date
name: v1alpha1
schema:
openAPIV3Schema:
properties:
spec:
description: 'Extend the functionality provided by the Istio proxy through
WebAssembly filters. See more details at: https://istio.io/docs/reference/config/proxy_extensions/wasm-plugin.html'
properties:
imagePullPolicy:
enum:
- UNSPECIFIED_POLICY
- IfNotPresent
- Always
type: string
imagePullSecret:
description: Credentials to use for OCI image pulling.
type: string
phase:
description: Determines where in the filter chain this WasmPlugin
is to be injected.
enum:
- UNSPECIFIED_PHASE
- AUTHN
- AUTHZ
- STATS
type: string
pluginConfig:
description: The configuration that will be passed on to the plugin.
type: object
x-kubernetes-preserve-unknown-fields: true
pluginName:
type: string
priority:
description: Determines ordering of WasmPlugins in the same phase.
nullable: true
type: integer
selector:
properties:
matchLabels:
additionalProperties:
type: string
type: object
type: object
sha256:
description: SHA256 checksum that will be used to verify Wasm module
or OCI container.
type: string
url:
description: URL of a Wasm module or OCI container.
type: string
verificationKey:
type: string
vmConfig:
description: Configuration for a Wasm VM.
properties:
env:
description: Specifies environment variables to be injected to
this VM.
items:
properties:
name:
type: string
value:
description: Value for the environment variable.
type: string
valueFrom:
enum:
- INLINE
- HOST
type: string
type: object
type: array
type: object
type: object
status:
type: object
x-kubernetes-preserve-unknown-fields: true
type: object
served: true
storage: true
subresources:
status: {}
`
func getNewComponent(spec string, name string) v1alpha1.Component {
comp := v1alpha1.NewComponent()
comp.Spec = spec
meta := map[string]interface{}{
ComponentMetaNameKey: name,
}
comp.Metadata = meta
return comp
}
func TestGenerate(t *testing.T) {
var tests = []struct {
crd string
want v1alpha1.Component
}{
{istioCrd, getNewComponent("", "WasmPlugin")},
}
for _, tt := range tests {
t.Run("generateComponent", func(t *testing.T) {
got, _ := Generate(tt.crd)
if !reflect.DeepEqual(got.Metadata, tt.want.Metadata) {
t.Errorf("got %v, want %v", got, tt.want)
}
if !(got.Kind == tt.want.Kind) {
t.Errorf("got %v, want %v", got, tt.want)
}
if !(got.APIVersion == tt.want.APIVersion) {
t.Errorf("got %v, want %v", got, tt.want)
}
if got.Spec == "" {
t.Errorf("got %v, want %v", got, tt.want)
}
})
}
}