@@ -163,6 +163,67 @@ class AnsibleResourceModelSourceSpec extends Specification {
163
163
then : " throws an exception because data is too big to be precessed"
164
164
thrown(ResourceModelSourceException )
165
165
}
166
+ void " structured data like ports is serialized as JSON when gather facts is false" () {
167
+ given :
168
+ def nodeName = ' NODE_JSON'
169
+ def structuredPorts = [
170
+ [port : 22 , protocol : ' tcp' , service : ' ssh' , state : ' open' ],
171
+ [port : 80 , protocol : ' tcp' , service : ' http' , state : ' open' ]
172
+ ]
173
+
174
+ Framework framework = Mock (Framework ) {
175
+ getPropertyLookup() >> Mock (IPropertyLookup ){
176
+ getProperty(" framework.tmp.dir" ) >> ' /tmp'
177
+ }
178
+ getBaseDir() >> Mock (File ) {
179
+ getAbsolutePath() >> ' /tmp'
180
+ }
181
+ }
182
+ ResourceModelSource plugin = new AnsibleResourceModelSource (framework)
183
+ Properties config = new Properties ()
184
+ config. put(' project' , ' project_1' )
185
+ config. put(AnsibleDescribable . ANSIBLE_GATHER_FACTS , ' false' )
186
+ plugin. configure(config)
187
+
188
+ Services services = Mock (Services ) {
189
+ getService(KeyStorageTree . class) >> Mock (KeyStorageTree )
190
+ }
191
+ plugin. setServices(services)
192
+
193
+ def host = [(nodeName): [
194
+ ' ports' : structuredPorts
195
+ ]]
196
+ def hosts = [' hosts' : host]
197
+ def groups = [' ungrouped' : hosts]
198
+ def children = [' children' : groups]
199
+ def all = [' all' : children]
200
+
201
+ Yaml yaml = new Yaml ()
202
+ String result = yaml. dump(all)
203
+
204
+ AnsibleInventoryListBuilder inventoryListBuilder = Mock (AnsibleInventoryListBuilder ) {
205
+ build() >> Mock (AnsibleInventoryList ) {
206
+ getNodeList() >> result
207
+ }
208
+ }
209
+
210
+ plugin. ansibleInventoryListBuilder = inventoryListBuilder
211
+
212
+ when :
213
+ INodeSet nodes = plugin. getNodes()
214
+ INodeEntry node = nodes. getNode(nodeName)
215
+
216
+ then :
217
+ node != null
218
+ node. getAttributes(). containsKey(" ports" )
219
+
220
+ and :
221
+ def portsJson = node. getAttributes(). get(" ports" )
222
+ portsJson. startsWith(" [" )
223
+ portsJson. contains(" \" port\" :22" )
224
+ portsJson. contains(" \" service\" :\" ssh\" " )
225
+ }
226
+
166
227
167
228
void " tag hosts is empty" () {
168
229
given :
0 commit comments