how to test the result of applying a puppet template to given test parameters

本秂侑毒 提交于 2019-12-04 09:46:39

I dont think you need the openstruct stuff. This works for me:

require 'erb'
#Test Variables
jmx_port = 9200
@markets = ['CH', 'FR']

temp = File.open("testerb.erb", "rb").read;
renderer = ERB.new(temp)
puts output = renderer.result()

Though I did have to alter your template a fraction:

I've removed the - from the -%> you had in your template. These prevented it from compiling, as they're supposed to be paired with <%=

{
  "servers" : [ {
    "port" : "<%= jmx_port %>",
    "host" : "localhost",

    "queries" : [
      <% @markets.each do |market| %>
    {
      "outputWriters" : [ {
        "@class" : "com.googlecode.jmxtrans.model.output.StdOutWriter",
      } ],
      "obj" : "solr/market_<%= market %>:type=queryResultCache,id=org.apache.solr.search.LRUCache",
      "attr" : [ "hits","hitratio"]
    },
    <% end %>
    ],
    "numQueryThreads" : 2
  } ]
}

If you turn on trim mode for ERB, you don't have to remove the "-%>" from the template:

renderer = ERB.new(temp, nil, '-')
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!