ConfigEvalEngine implements TemplateEngine { protected Config eval(Config config, Config params) throws TemplateException { ObjectNode object = config.convert(ObjectNode.class); ObjectNode built = new Context(params).evalObjectRecursive(object); return config.getFactory().create(built); } @Inject  ConfigEvalEngine(); @Override String template(String content, Config params);  }
@Test public void testBasic() throws Exception { assertThat( engine.eval(loadYamlResource("/io/digdag/core/agent/eval/basic.dig"), params()), is(loadYamlResource("/io/digdag/core/agent/eval/basic_expected.dig"))); }
@Test public void testLiteral() throws Exception { assertThat( engine.eval(loadYamlResource("/io/digdag/core/agent/eval/literal.dig"), params()), is(loadYamlResource("/io/digdag/core/agent/eval/literal_expected.dig"))); }
@Test public void undefinedVariable() throws Exception { exception.expect(TemplateException.class); exception.expectMessage(containsString("ReferenceError")); exception.expectMessage(containsString("no_such_var")); engine.eval(newConfig().set("key", "${no_such_var}"), params()); }
@Test public void undefinedField() throws Exception { assertThat( engine.eval(newConfig().set("key", "${timezone.no_such_field}"), params()) .get("key", String.class), is("")); }
@Test public void undefinedFieldAccess() throws Exception { exception.expect(TemplateException.class); exception.expectMessage(containsString("TypeError")); exception.expectMessage(containsString("invalid_access")); engine.eval(newConfig().set("key", "${timezone.no_such_field.invalid_access}"), params()); }
@Test public void testMoment() throws Exception { assertThat( engine.eval(loadYamlResource("/io/digdag/core/agent/eval/moment.dig"), params()), is(loadYamlResource("/io/digdag/core/agent/eval/moment_expected.dig"))); }
@Test public void testMomentTimeZone() throws Exception { assertThat( engine.eval(loadYamlResource("/io/digdag/core/agent/eval/moment.dig"), params().set("timezone", "Asia/Tokyo")), is(loadYamlResource("/io/digdag/core/agent/eval/moment_expected_jst.dig"))); }
@Test public void testMomentDstTimeZone() throws Exception { assertThat( engine.eval(loadYamlResource("/io/digdag/core/agent/eval/moment.dig"), params().set("timezone", "America/Los_Angeles")), is(loadYamlResource("/io/digdag/core/agent/eval/moment_expected_pst_pdt.dig"))); }
@Test public void momentNowIsAvailable() throws Exception { assertThat( engine.eval(newConfig().set("key", "${moment().format()}"), params()).get("key", String.class), not(is(""))); }