K8sSpecTemplate extends HashMap<String, Object> { public String render(File templateFile) throws IOException { String template = FileUtils.readFileToString(templateFile, Charset.defaultCharset()); return render(template); }  String render(File templateFile); String render(String template); void loadProperties(Properties properties);  }
@Test public void testRender() { K8sSpecTemplate template = new K8sSpecTemplate(); template.put("name", "world"); String spec = template.render("Hello {{name}}"); assertEquals("Hello world", spec); }
@Test public void testObject() { K8sSpecTemplate template = new K8sSpecTemplate(); template.put("k8s", ImmutableMap.of("key", "world")); String spec = template.render("Hello {{k8s.key}}"); assertEquals("Hello world", spec); }
@Test public void testRenderWithStrip() { K8sSpecTemplate template = new K8sSpecTemplate(); template.put("test", "test"); String spec = template.render( " {% if test == \"test\" %}\n" + " After commit\n" + " {% endif %}\n"); assertEquals(" After commit\n", spec); }
@Test public void testIterate() { K8sSpecTemplate template = new K8sSpecTemplate(); template.put("dict", ImmutableMap.of( "k1", "v1", "k2", "v2" )); String spec = template.render( "{% for key, value in dict.items() %}" + "key = {{key}}, value = {{value}}\n" + "{% endfor %}" ); assertEquals( "key = k1, value = v1\n" + "key = k2, value = v2\n", spec); }