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
@@ -47,47 +46,42 @@ func testConfigurationMetadata(t *testing.T, context spec.G, it spec.S) {
47
46
})
48
47
49
48
context ("from path" , func () {
50
- // ... (existing test cases)
51
49
52
- it ("returns dataflow decoded contents with names" , func () {
53
- Expect (os .MkdirAll (filepath .Join (path , "META-INF" ), 0755 )).To (Succeed ())
54
- Expect (ioutil .WriteFile (filepath .Join (path , "META-INF" , "spring-configuration-metadata.json" ),
55
- []byte (`{ "properties": [ { "name": "alpha", "sourceType": "alpha" } ] }` ), 0644 )).To (Succeed ())
56
- Expect (ioutil .WriteFile (filepath .Join (path , "META-INF" , "dataflow-configuration-metadata.properties" ),
57
- []byte ("configuration-properties.names=alpha" ), 0644 )).To (Succeed ())
50
+ it ("returns empty if file does not exist" , func () {
51
+ Expect (boot .NewConfigurationMetadataFromPath (path )).To (BeZero ())
52
+ })
58
53
59
- cm , err := boot .NewConfigurationMetadataFromPath (path )
60
- Expect (err ).NotTo (HaveOccurred ())
54
+ it ("returns decoded contents" , func () {
55
+ Expect (os .MkdirAll (filepath .Join (path , "META-INF" ), 0755 )).To (Succeed ())
56
+ Expect (os .WriteFile (filepath .Join (path , "META-INF" , "spring-configuration-metadata.json" ),
57
+ []byte (`{ "groups": [ { "name": "alpha" } ] }` ), 0644 )).To (Succeed ())
61
58
62
- Expect (boot .NewDataFlowConfigurationMetadata (path , cm )).To (Equal (boot.ConfigurationMetadata {
63
- Properties : []boot.Property {{Name : "alpha" , SourceType : "alpha" }},
59
+ Expect (boot .NewConfigurationMetadataFromPath (path )).To (Equal (boot.ConfigurationMetadata {
60
+ Groups : []boot.Group {{Name : "alpha" }},
64
61
}))
65
62
})
66
63
67
- it ("returns combined dataflow decoded contents with classes and names " , func () {
64
+ it ("returns dataflow decoded contents" , func () {
68
65
Expect (os .MkdirAll (filepath .Join (path , "META-INF" ), 0755 )).To (Succeed ())
69
- Expect (ioutil .WriteFile (filepath .Join (path , "META-INF" , "spring-configuration-metadata.json" ),
70
- []byte (`{ "groups": [ { "name": "alpha", "sourceType": "alpha" }, { "name": "beta", "sourceType": "beta" } ] }` ), 0644 )). To ( Succeed ( ))
71
- Expect (ioutil .WriteFile (filepath .Join (path , "META-INF" , "dataflow-configuration-metadata.properties" ),
72
- []byte ("configuration-properties.classes=alpha\n configuration-properties.names=beta " ), 0644 )). To ( Succeed ( ))
66
+ Expect (os .WriteFile (filepath .Join (path , "META-INF" , "spring-configuration-metadata.json" ),
67
+ []byte (`{ "groups": [ { "name": "alpha", "sourceType": "alpha" } ] }` ), 0644 ))
68
+ Expect (os .WriteFile (filepath .Join (path , "META-INF" , "dataflow-configuration-metadata.properties" ),
69
+ []byte ("configuration-properties.classes=alpha" ), 0644 ))
73
70
74
71
cm , err := boot .NewConfigurationMetadataFromPath (path )
75
72
Expect (err ).NotTo (HaveOccurred ())
76
73
77
74
Expect (boot .NewDataFlowConfigurationMetadata (path , cm )).To (Equal (boot.ConfigurationMetadata {
78
- Groups : []boot.Group {
79
- {Name : "alpha" , SourceType : "alpha" },
80
- {Name : "beta" , SourceType : "beta" },
81
- },
75
+ Groups : []boot.Group {{Name : "alpha" , SourceType : "alpha" }},
82
76
}))
83
77
})
84
78
85
- it ("handles empty names gracefully " , func () {
79
+ it ("returns dataflow decoded contents handling trailing comma correctly " , func () {
86
80
Expect (os .MkdirAll (filepath .Join (path , "META-INF" ), 0755 )).To (Succeed ())
87
- Expect (ioutil .WriteFile (filepath .Join (path , "META-INF" , "spring-configuration-metadata.json" ),
88
- []byte (`{ "properties": [ { "name": "alpha", "sourceType": "alpha" } ] }` ), 0644 )). To ( Succeed ( ))
89
- Expect (ioutil .WriteFile (filepath .Join (path , "META-INF" , "dataflow-configuration-metadata.properties" ),
90
- []byte ("configuration-properties.names= " ), 0644 )). To ( Succeed ( ))
81
+ Expect (os .WriteFile (filepath .Join (path , "META-INF" , "spring-configuration-metadata.json" ),
82
+ []byte (`{ "properties": [ { "name": "alpha", "sourceType": "alpha" }, { "name": "beta" } ] }` ), 0644 ))
83
+ Expect (os .WriteFile (filepath .Join (path , "META-INF" , "dataflow-configuration-metadata.properties" ),
84
+ []byte ("configuration-properties.classes=alpha, " ), 0644 ))
91
85
92
86
cm , err := boot .NewConfigurationMetadataFromPath (path )
93
87
Expect (err ).NotTo (HaveOccurred ())
@@ -96,64 +90,61 @@ func testConfigurationMetadata(t *testing.T, context spec.G, it spec.S) {
96
90
Properties : []boot.Property {{Name : "alpha" , SourceType : "alpha" }},
97
91
}))
98
92
})
99
- })
100
-
101
93
102
- func testConfigurationMetadata (t * testing.T , context spec.G , it spec.S ) {
103
- var (
104
- Expect = NewWithT (t ).Expect
105
-
106
- path string
107
- )
108
-
109
- it .Before (func () {
110
- var err error
111
-
112
- path , err = ioutil .TempDir ("" , "configuration-metadata" )
113
- Expect (err ).NotTo (HaveOccurred ())
114
- })
115
-
116
- it .After (func () {
117
- Expect (os .RemoveAll (path )).To (Succeed ())
118
- })
94
+ it ("returns dataflow decoded contents" , func () {
95
+ Expect (os .MkdirAll (filepath .Join (path , "META-INF" ), 0755 )).To (Succeed ())
96
+ Expect (os .WriteFile (filepath .Join (path , "META-INF" , "spring-configuration-metadata.json" ),
97
+ []byte (`{ "groups": [ { "name": "alpha", "sourceType": "alpha" } ] }` ), 0644 )).To (Succeed ())
98
+ Expect (os .WriteFile (filepath .Join (path , "META-INF" , "dataflow-configuration-metadata-whitelist.properties" ),
99
+ []byte ("configuration-properties.classes=alpha" ), 0644 )).To (Succeed ())
119
100
120
- context ("from path" , func () {
101
+ cm , err := boot .NewConfigurationMetadataFromPath (path )
102
+ Expect (err ).NotTo (HaveOccurred ())
121
103
122
- it ("returns empty if file does not exist" , func () {
123
- Expect (boot .NewConfigurationMetadataFromPath (path )).To (BeZero ())
104
+ Expect (boot .NewDataFlowConfigurationMetadata (path , cm )).To (Equal (boot.ConfigurationMetadata {
105
+ Groups : []boot.Group {{Name : "alpha" , SourceType : "alpha" }},
106
+ }))
124
107
})
125
108
126
- it ("returns decoded contents" , func () {
109
+ it ("returns dataflow decoded contents with names " , func () {
127
110
Expect (os .MkdirAll (filepath .Join (path , "META-INF" ), 0755 )).To (Succeed ())
128
- Expect (ioutil .WriteFile (filepath .Join (path , "META-INF" , "spring-configuration-metadata.json" ),
129
- []byte (`{ "groups": [ { "name": "alpha" } ] }` ), 0644 )).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 ())
130
115
131
- Expect (boot .NewConfigurationMetadataFromPath (path )).To (Equal (boot.ConfigurationMetadata {
132
- Groups : []boot.Group {{Name : "alpha" }},
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" }},
133
121
}))
134
122
})
135
123
136
- it ("returns dataflow decoded contents" , func () {
124
+ it ("returns combined dataflow decoded contents with classes and names " , func () {
137
125
Expect (os .MkdirAll (filepath .Join (path , "META-INF" ), 0755 )).To (Succeed ())
138
- Expect (ioutil .WriteFile (filepath .Join (path , "META-INF" , "spring-configuration-metadata.json" ),
139
- []byte (`{ "groups": [ { "name": "alpha", "sourceType": "alpha" } ] }` ), 0644 ))
140
- Expect (ioutil .WriteFile (filepath .Join (path , "META-INF" , "dataflow-configuration-metadata.properties" ),
141
- []byte ("configuration-properties.classes=alpha" ), 0644 ))
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 ( ))
142
130
143
131
cm , err := boot .NewConfigurationMetadataFromPath (path )
144
132
Expect (err ).NotTo (HaveOccurred ())
145
133
146
134
Expect (boot .NewDataFlowConfigurationMetadata (path , cm )).To (Equal (boot.ConfigurationMetadata {
147
- Groups : []boot.Group {{Name : "alpha" , SourceType : "alpha" }},
135
+ Groups : []boot.Group {
136
+ {Name : "alpha" , SourceType : "alpha" },
137
+ {Name : "beta" , SourceType : "beta" },
138
+ },
148
139
}))
149
140
})
150
141
151
- it ("returns dataflow decoded contents handling trailing comma correctly " , func () {
142
+ it ("handles missing names properly " , func () {
152
143
Expect (os .MkdirAll (filepath .Join (path , "META-INF" ), 0755 )).To (Succeed ())
153
- Expect (ioutil .WriteFile (filepath .Join (path , "META-INF" , "spring-configuration-metadata.json" ),
154
- []byte (`{ "properties": [ { "name": "alpha", "sourceType": "alpha" }, { "name": "beta" } ] }` ), 0644 ))
155
- Expect (ioutil .WriteFile (filepath .Join (path , "META-INF" , "dataflow-configuration-metadata.properties" ),
156
- []byte ("configuration-properties.classes =alpha, " ), 0644 ))
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 ( ))
157
148
158
149
cm , err := boot .NewConfigurationMetadataFromPath (path )
159
150
Expect (err ).NotTo (HaveOccurred ())
@@ -163,19 +154,17 @@ func testConfigurationMetadata(t *testing.T, context spec.G, it spec.S) {
163
154
}))
164
155
})
165
156
166
- it ("returns dataflow decoded contents " , func () {
157
+ it ("handles empty names gracefully " , func () {
167
158
Expect (os .MkdirAll (filepath .Join (path , "META-INF" ), 0755 )).To (Succeed ())
168
- Expect (ioutil .WriteFile (filepath .Join (path , "META-INF" , "spring-configuration-metadata.json" ),
169
- []byte (`{ "groups ": [ { "name": "alpha", "sourceType": "alpha" } ] }` ), 0644 )).To (Succeed ())
170
- Expect (ioutil .WriteFile (filepath .Join (path , "META-INF" , "dataflow-configuration-metadata-whitelist .properties" ),
171
- []byte ("configuration-properties.classes=alpha " ), 0644 )).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 ())
172
163
173
164
cm , err := boot .NewConfigurationMetadataFromPath (path )
174
165
Expect (err ).NotTo (HaveOccurred ())
175
166
176
- Expect (boot .NewDataFlowConfigurationMetadata (path , cm )).To (Equal (boot.ConfigurationMetadata {
177
- Groups : []boot.Group {{Name : "alpha" , SourceType : "alpha" }},
178
- }))
167
+ Expect (boot .NewDataFlowConfigurationMetadata (path , cm )).To (Equal (boot.ConfigurationMetadata {}))
179
168
})
180
169
})
181
170
@@ -203,14 +192,14 @@ func testConfigurationMetadata(t *testing.T, context spec.G, it spec.S) {
203
192
204
193
it ("returns true if the file does exist" , func () {
205
194
Expect (os .MkdirAll (filepath .Join (path , "META-INF" ), 0755 )).To (Succeed ())
206
- 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" ),
207
196
[]byte ("configuration-properties.classes=alpha" ), 0644 )).To (Succeed ())
208
197
Expect (boot .DataFlowConfigurationExists (path )).To (BeFalse ())
209
198
})
210
199
211
200
it ("return false and the error if the file cannot be read" , func () {
212
201
Expect (os .MkdirAll (filepath .Join (path , "META-INF" ), 0755 )).To (Succeed ())
213
- 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" ),
214
203
[]byte ("configuration-properties.classes=alpha" ), 0644 )).To (Succeed ())
215
204
216
205
Expect (os .Chmod (filepath .Join (path , "META-INF" ), 0000 )).To (Succeed ())
0 commit comments