17
17
package boot_test
18
18
19
19
import (
20
- "io/ioutil"
21
20
"os"
22
21
"path/filepath"
23
22
"testing"
@@ -38,7 +37,7 @@ func testConfigurationMetadata(t *testing.T, context spec.G, it spec.S) {
38
37
it .Before (func () {
39
38
var err error
40
39
41
- path , err = ioutil . TempDir ("" , "configuration-metadata" )
40
+ path , err = os . MkdirTemp ("" , "configuration-metadata" )
42
41
Expect (err ).NotTo (HaveOccurred ())
43
42
})
44
43
@@ -54,7 +53,7 @@ func testConfigurationMetadata(t *testing.T, context spec.G, it spec.S) {
54
53
55
54
it ("returns decoded contents" , func () {
56
55
Expect (os .MkdirAll (filepath .Join (path , "META-INF" ), 0755 )).To (Succeed ())
57
- Expect (ioutil .WriteFile (filepath .Join (path , "META-INF" , "spring-configuration-metadata.json" ),
56
+ Expect (os .WriteFile (filepath .Join (path , "META-INF" , "spring-configuration-metadata.json" ),
58
57
[]byte (`{ "groups": [ { "name": "alpha" } ] }` ), 0644 )).To (Succeed ())
59
58
60
59
Expect (boot .NewConfigurationMetadataFromPath (path )).To (Equal (boot.ConfigurationMetadata {
@@ -64,9 +63,9 @@ func testConfigurationMetadata(t *testing.T, context spec.G, it spec.S) {
64
63
65
64
it ("returns dataflow decoded contents" , func () {
66
65
Expect (os .MkdirAll (filepath .Join (path , "META-INF" ), 0755 )).To (Succeed ())
67
- Expect (ioutil .WriteFile (filepath .Join (path , "META-INF" , "spring-configuration-metadata.json" ),
66
+ Expect (os .WriteFile (filepath .Join (path , "META-INF" , "spring-configuration-metadata.json" ),
68
67
[]byte (`{ "groups": [ { "name": "alpha", "sourceType": "alpha" } ] }` ), 0644 ))
69
- Expect (ioutil .WriteFile (filepath .Join (path , "META-INF" , "dataflow-configuration-metadata.properties" ),
68
+ Expect (os .WriteFile (filepath .Join (path , "META-INF" , "dataflow-configuration-metadata.properties" ),
70
69
[]byte ("configuration-properties.classes=alpha" ), 0644 ))
71
70
72
71
cm , err := boot .NewConfigurationMetadataFromPath (path )
@@ -79,9 +78,9 @@ func testConfigurationMetadata(t *testing.T, context spec.G, it spec.S) {
79
78
80
79
it ("returns dataflow decoded contents handling trailing comma correctly" , func () {
81
80
Expect (os .MkdirAll (filepath .Join (path , "META-INF" ), 0755 )).To (Succeed ())
82
- Expect (ioutil .WriteFile (filepath .Join (path , "META-INF" , "spring-configuration-metadata.json" ),
81
+ Expect (os .WriteFile (filepath .Join (path , "META-INF" , "spring-configuration-metadata.json" ),
83
82
[]byte (`{ "properties": [ { "name": "alpha", "sourceType": "alpha" }, { "name": "beta" } ] }` ), 0644 ))
84
- Expect (ioutil .WriteFile (filepath .Join (path , "META-INF" , "dataflow-configuration-metadata.properties" ),
83
+ Expect (os .WriteFile (filepath .Join (path , "META-INF" , "dataflow-configuration-metadata.properties" ),
85
84
[]byte ("configuration-properties.classes=alpha," ), 0644 ))
86
85
87
86
cm , err := boot .NewConfigurationMetadataFromPath (path )
@@ -94,9 +93,9 @@ func testConfigurationMetadata(t *testing.T, context spec.G, it spec.S) {
94
93
95
94
it ("returns dataflow decoded contents" , func () {
96
95
Expect (os .MkdirAll (filepath .Join (path , "META-INF" ), 0755 )).To (Succeed ())
97
- Expect (ioutil .WriteFile (filepath .Join (path , "META-INF" , "spring-configuration-metadata.json" ),
96
+ Expect (os .WriteFile (filepath .Join (path , "META-INF" , "spring-configuration-metadata.json" ),
98
97
[]byte (`{ "groups": [ { "name": "alpha", "sourceType": "alpha" } ] }` ), 0644 )).To (Succeed ())
99
- Expect (ioutil .WriteFile (filepath .Join (path , "META-INF" , "dataflow-configuration-metadata-whitelist.properties" ),
98
+ Expect (os .WriteFile (filepath .Join (path , "META-INF" , "dataflow-configuration-metadata-whitelist.properties" ),
100
99
[]byte ("configuration-properties.classes=alpha" ), 0644 )).To (Succeed ())
101
100
102
101
cm , err := boot .NewConfigurationMetadataFromPath (path )
@@ -106,6 +105,67 @@ func testConfigurationMetadata(t *testing.T, context spec.G, it spec.S) {
106
105
Groups : []boot.Group {{Name : "alpha" , SourceType : "alpha" }},
107
106
}))
108
107
})
108
+
109
+ it ("returns dataflow decoded contents with names" , func () {
110
+ Expect (os .MkdirAll (filepath .Join (path , "META-INF" ), 0755 )).To (Succeed ())
111
+ Expect (os .WriteFile (filepath .Join (path , "META-INF" , "spring-configuration-metadata.json" ),
112
+ []byte (`{ "properties": [ { "name": "alpha", "sourceType": "alpha" } ] }` ), 0644 )).To (Succeed ())
113
+ Expect (os .WriteFile (filepath .Join (path , "META-INF" , "dataflow-configuration-metadata.properties" ),
114
+ []byte ("configuration-properties.names=alpha" ), 0644 )).To (Succeed ())
115
+
116
+ cm , err := boot .NewConfigurationMetadataFromPath (path )
117
+ Expect (err ).NotTo (HaveOccurred ())
118
+
119
+ Expect (boot .NewDataFlowConfigurationMetadata (path , cm )).To (Equal (boot.ConfigurationMetadata {
120
+ Properties : []boot.Property {{Name : "alpha" , SourceType : "alpha" }},
121
+ }))
122
+ })
123
+
124
+ it ("returns combined dataflow decoded contents with classes and names" , func () {
125
+ Expect (os .MkdirAll (filepath .Join (path , "META-INF" ), 0755 )).To (Succeed ())
126
+ Expect (os .WriteFile (filepath .Join (path , "META-INF" , "spring-configuration-metadata.json" ),
127
+ []byte (`{ "groups": [ { "name": "alpha", "sourceType": "alpha" }, { "name": "beta", "sourceType": "beta" } ] }` ), 0644 )).To (Succeed ())
128
+ Expect (os .WriteFile (filepath .Join (path , "META-INF" , "dataflow-configuration-metadata.properties" ),
129
+ []byte ("configuration-properties.classes=alpha\n configuration-properties.names=beta" ), 0644 )).To (Succeed ())
130
+
131
+ cm , err := boot .NewConfigurationMetadataFromPath (path )
132
+ Expect (err ).NotTo (HaveOccurred ())
133
+
134
+ Expect (boot .NewDataFlowConfigurationMetadata (path , cm )).To (Equal (boot.ConfigurationMetadata {
135
+ Groups : []boot.Group {
136
+ {Name : "alpha" , SourceType : "alpha" },
137
+ {Name : "beta" , SourceType : "beta" },
138
+ },
139
+ }))
140
+ })
141
+
142
+ it ("handles missing names properly" , func () {
143
+ Expect (os .MkdirAll (filepath .Join (path , "META-INF" ), 0755 )).To (Succeed ())
144
+ Expect (os .WriteFile (filepath .Join (path , "META-INF" , "spring-configuration-metadata.json" ),
145
+ []byte (`{ "properties": [ { "name": "alpha", "sourceType": "alpha" }, { "name": "beta", "sourceType": "beta" } ] }` ), 0644 )).To (Succeed ())
146
+ Expect (os .WriteFile (filepath .Join (path , "META-INF" , "dataflow-configuration-metadata.properties" ),
147
+ []byte ("configuration-properties.names=alpha" ), 0644 )).To (Succeed ())
148
+
149
+ cm , err := boot .NewConfigurationMetadataFromPath (path )
150
+ Expect (err ).NotTo (HaveOccurred ())
151
+
152
+ Expect (boot .NewDataFlowConfigurationMetadata (path , cm )).To (Equal (boot.ConfigurationMetadata {
153
+ Properties : []boot.Property {{Name : "alpha" , SourceType : "alpha" }},
154
+ }))
155
+ })
156
+
157
+ it ("handles empty names gracefully" , func () {
158
+ Expect (os .MkdirAll (filepath .Join (path , "META-INF" ), 0755 )).To (Succeed ())
159
+ Expect (os .WriteFile (filepath .Join (path , "META-INF" , "spring-configuration-metadata.json" ),
160
+ []byte (`{ "properties": [ { "name": "alpha", "sourceType": "alpha" } ] }` ), 0644 )).To (Succeed ())
161
+ Expect (os .WriteFile (filepath .Join (path , "META-INF" , "dataflow-configuration-metadata.properties" ),
162
+ []byte ("configuration-properties.names=" ), 0644 )).To (Succeed ())
163
+
164
+ cm , err := boot .NewConfigurationMetadataFromPath (path )
165
+ Expect (err ).NotTo (HaveOccurred ())
166
+
167
+ Expect (boot .NewDataFlowConfigurationMetadata (path , cm )).To (Equal (boot.ConfigurationMetadata {}))
168
+ })
109
169
})
110
170
111
171
context ("from JAR" , func () {
@@ -132,14 +192,14 @@ func testConfigurationMetadata(t *testing.T, context spec.G, it spec.S) {
132
192
133
193
it ("returns true if the file does exist" , func () {
134
194
Expect (os .MkdirAll (filepath .Join (path , "META-INF" ), 0755 )).To (Succeed ())
135
- Expect (ioutil .WriteFile (filepath .Join (path , "META-INF" , "dataflow-configuration-metadata-whitelist.properties" ),
195
+ Expect (os .WriteFile (filepath .Join (path , "META-INF" , "dataflow-configuration-metadata-whitelist.properties" ),
136
196
[]byte ("configuration-properties.classes=alpha" ), 0644 )).To (Succeed ())
137
197
Expect (boot .DataFlowConfigurationExists (path )).To (BeFalse ())
138
198
})
139
199
140
200
it ("return false and the error if the file cannot be read" , func () {
141
201
Expect (os .MkdirAll (filepath .Join (path , "META-INF" ), 0755 )).To (Succeed ())
142
- Expect (ioutil .WriteFile (filepath .Join (path , "META-INF" , "dataflow-configuration-metadata-whitelist.properties" ),
202
+ Expect (os .WriteFile (filepath .Join (path , "META-INF" , "dataflow-configuration-metadata-whitelist.properties" ),
143
203
[]byte ("configuration-properties.classes=alpha" ), 0644 )).To (Succeed ())
144
204
145
205
Expect (os .Chmod (filepath .Join (path , "META-INF" ), 0000 )).To (Succeed ())
0 commit comments