-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathstackit_test.go
More file actions
140 lines (120 loc) · 3.81 KB
/
stackit_test.go
File metadata and controls
140 lines (120 loc) · 3.81 KB
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
package ccm
import (
"bytes"
"strings"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
stackitconfig "github.com/stackitcloud/cloud-provider-stackit/pkg/stackit/config"
)
var _ = Describe("GetConfig", func() {
It("should parse valid YAML configuration", func() {
validYAML := `
global:
projectId: "test-project"
region: "eu01"
apiEndpoints:
loadBalancerApi: "https://load-balancer.api.eu01.stackit.cloud"
metadata:
searchOrder: "metadataService,configDrive"
loadBalancer:
networkId: "test-network"
`
config, err := GetConfig(strings.NewReader(validYAML))
Expect(err).NotTo(HaveOccurred())
Expect(config.Global.ProjectID).To(Equal("test-project"))
Expect(config.Global.Region).To(Equal("eu01"))
Expect(config.Global.APIEndpoints.LoadBalancerAPI).To(Equal("https://load-balancer.api.eu01.stackit.cloud"))
Expect(config.Metadata.SearchOrder).To(Equal("metadataService,configDrive"))
Expect(config.LoadBalancer.NetworkID).To(Equal("test-network"))
})
It("should handle missing optional fields", func() {
minimalYAML := `
global:
projectId: "my-project"
region: "eu01"
loadBalancer:
networkId: "my-network"
`
config, err := GetConfig(strings.NewReader(minimalYAML))
Expect(err).NotTo(HaveOccurred())
Expect(config.Global.ProjectID).To(Equal("my-project"))
Expect(config.Global.Region).To(Equal("eu01"))
Expect(config.Global.APIEndpoints.LoadBalancerAPI).To(BeEmpty())
Expect(config.LoadBalancer.NetworkID).To(Equal("my-network"))
})
It("should handle configuration with extra labels", func() {
yamlWithLabels := `
global:
projectId: "test-project"
region: "eu01"
loadBalancer:
networkId: "test-network"
extraLabels:
environment: "production"
team: "platform"
`
config, err := GetConfig(strings.NewReader(yamlWithLabels))
Expect(err).NotTo(HaveOccurred())
Expect(config.LoadBalancer.ExtraLabels).To(HaveKeyWithValue("environment", "production"))
Expect(config.LoadBalancer.ExtraLabels).To(HaveKeyWithValue("team", "platform"))
})
It("should return error for malformed YAML", func() {
invalidYAML := `
global:
projectId: "test-project"
region: "eu01"
invalid yaml syntax here [[[
`
_, err := GetConfig(strings.NewReader(invalidYAML))
Expect(err).To(HaveOccurred())
})
It("should handle empty YAML gracefully", func() {
emptyYAML := ``
config, err := GetConfig(strings.NewReader(emptyYAML))
Expect(err).NotTo(HaveOccurred())
Expect(config).To(Equal(stackitconfig.CCMConfig{}))
})
It("should return error for invalid YAML structure", func() {
invalidStructure := `
this is not valid yaml structure
- random: content
`
_, err := GetConfig(strings.NewReader(invalidStructure))
Expect(err).To(HaveOccurred())
})
It("should handle YAML with comments", func() {
yamlWithComments := `
# This is a comment
global:
projectId: "test-project" # inline comment
region: "eu01"
# Another comment
loadBalancer:
networkId: "test-network"
`
config, err := GetConfig(strings.NewReader(yamlWithComments))
Expect(err).NotTo(HaveOccurred())
Expect(config.Global.ProjectID).To(Equal("test-project"))
Expect(config.LoadBalancer.NetworkID).To(Equal("test-network"))
})
It("should handle YAML with different string quote styles", func() {
mixedQuotesYAML := `
global:
projectId: "test-project"
region: 'eu01'
loadBalancer:
networkId: test-network
`
config, err := GetConfig(strings.NewReader(mixedQuotesYAML))
Expect(err).NotTo(HaveOccurred())
Expect(config.Global.ProjectID).To(Equal("test-project"))
Expect(config.Global.Region).To(Equal("eu01"))
Expect(config.LoadBalancer.NetworkID).To(Equal("test-network"))
})
It("should handle empty reader gracefully", func() {
emptyReader := bytes.NewReader([]byte{})
config, err := GetConfig(emptyReader)
Expect(err).NotTo(HaveOccurred())
Expect(config).To(Equal(stackitconfig.CCMConfig{}))
})
})