Expressions syntax is now $var$
Instead of $$var$$. We make sure $$var$$ is left untouched. refs #11976
This commit is contained in:
parent
ddcfb09f58
commit
37c91050c7
|
@ -263,7 +263,7 @@ class IcingaConfigHelper
|
|||
}
|
||||
|
||||
private static function renderStringWithVariables($string) {
|
||||
$string = preg_replace('/\$\$([\w\.]+)\$\$/', '" + ${1} + "', $string);
|
||||
$string = preg_replace('/(?<!\$)\$([\w\.]+)\$(?!\$)/', '" + ${1} + "', $string);
|
||||
$string = '"' . $string . '"';
|
||||
if (substr($string, 0, 5) === '"" + ') {
|
||||
$string = substr($string, 5);
|
||||
|
|
|
@ -48,7 +48,7 @@ class CustomVariablesTest extends BaseTestCase
|
|||
{
|
||||
$vars = $this->newVars();
|
||||
$vars->bla = 'da';
|
||||
$vars->abc = '$$val$$';
|
||||
$vars->abc = '$val$';
|
||||
$expected = $this->indentVarsList(array(
|
||||
'vars.abc = val',
|
||||
'vars.bla = "da"'
|
||||
|
|
|
@ -83,19 +83,21 @@ class IcingaConfigHelperTest extends BaseTestCase
|
|||
|
||||
public function testRenderStringWithVariables()
|
||||
{
|
||||
$this->assertEquals(c::renderString('Before $$var$$', true), '"Before " + var');
|
||||
$this->assertEquals(c::renderString('$$var$$ After', true), 'var + " After"');
|
||||
$this->assertEquals(c::renderString('$$var$$', true), 'var');
|
||||
$this->assertEquals(c::renderString('Before $var$', true), '"Before " + var');
|
||||
$this->assertEquals(c::renderString('$var$ After', true), 'var + " After"');
|
||||
$this->assertEquals(c::renderString('$var$', true), 'var');
|
||||
$this->assertEquals(c::renderString('$$var$$', true), '"$$var$$"');
|
||||
$this->assertEquals(c::renderString('Before $$var$$ After', true), '"Before $$var$$ After"');
|
||||
$this->assertEquals(
|
||||
c::renderString('Before $$name$$ $$name$$ After', true),
|
||||
c::renderString('Before $name$ $name$ After', true),
|
||||
'"Before " + name + " " + name + " After"');
|
||||
$this->assertEquals(
|
||||
c::renderString('Before $$var1$$ $$var2$$ After', true),
|
||||
c::renderString('Before $var1$ $var2$ After', true),
|
||||
'"Before " + var1 + " " + var2 + " After"');
|
||||
$this->assertEquals(c::renderString('$$host.vars.custom$$', true), 'host.vars.custom');
|
||||
$this->assertEquals(c::renderString('$$var"$$', true), '"$$var\"$$"');
|
||||
$this->assertEquals(c::renderString('$host.vars.custom$', true), 'host.vars.custom');
|
||||
$this->assertEquals(c::renderString('$var"$', true), '"$var\"$"');
|
||||
$this->assertEquals(
|
||||
c::renderString('\tI am\rrendering\nproperly\fand I $$support$$ "multiple" $$variables$$\$', true),
|
||||
c::renderString('\tI am\rrendering\nproperly\fand I $support$ "multiple" $variables$\$', true),
|
||||
'"\\\\tI am\\\\rrendering\\\\nproperly\\\\fand I " + support + " \"multiple\" " + variables + "\\\\$"');
|
||||
}
|
||||
}
|
||||
|
|
|
@ -242,13 +242,13 @@ class IcingaServiceTest extends BaseTestCase
|
|||
|
||||
$db = $this->getDb();
|
||||
|
||||
$service = $this->service('___TEST___service_$$not_replaced$$');
|
||||
$service = $this->service('___TEST___service_$not_replaced$');
|
||||
$service->object_type = 'apply';
|
||||
$service->display_name = 'Service: $$replaced$$';
|
||||
$service->display_name = 'Service: $host.vars.replaced$';
|
||||
$service->assignments = array(
|
||||
'host.address="127.*"',
|
||||
);
|
||||
$service->{'vars.custom_var'} = '$$replaced$$';
|
||||
$service->{'vars.custom_var'} = '$host.vars.replaced$';
|
||||
$service->store($db);
|
||||
|
||||
$service = IcingaService::loadWithAutoIncId($service->id, $db);
|
||||
|
@ -266,10 +266,10 @@ class IcingaServiceTest extends BaseTestCase
|
|||
|
||||
$db = $this->getDb();
|
||||
|
||||
$service = $this->service('___TEST___service_$$not_replaced$$');
|
||||
$service = $this->service('___TEST___service_$not_replaced$');
|
||||
$service->object_type = 'object';
|
||||
$service->display_name = 'Service: $$not_replaced$$';
|
||||
$service->{'vars.custom_var'} = '$$not_replaced$$';
|
||||
$service->display_name = 'Service: $host.vars.not_replaced$';
|
||||
$service->{'vars.custom_var'} = '$host.vars.not_replaced$';
|
||||
$service->store($db);
|
||||
|
||||
$service = IcingaService::loadWithAutoIncId($service->id, $db);
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
apply Service "___TEST___service_$$not_replaced$$" {
|
||||
display_name = "Service: " + replaced
|
||||
vars.custom_var = replaced
|
||||
apply Service "___TEST___service_$not_replaced$" {
|
||||
display_name = "Service: " + host.vars.replaced
|
||||
vars.custom_var = host.vars.replaced
|
||||
vars.test1 = "string"
|
||||
vars.test2 = 17
|
||||
vars.test3 = false
|
||||
|
@ -11,6 +11,6 @@ apply Service "___TEST___service_$$not_replaced$$" {
|
|||
|
||||
assign where match("127.*", host.address)
|
||||
|
||||
import "host var overrides (Director)"
|
||||
import DirectorOverrideTemplate
|
||||
}
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
object Service "___TEST___service_$$not_replaced$$" {
|
||||
display_name = "Service: $$not_replaced$$"
|
||||
vars.custom_var = "$$not_replaced$$"
|
||||
object Service "___TEST___service_$not_replaced$" {
|
||||
display_name = "Service: $host.vars.not_replaced$"
|
||||
vars.custom_var = "$host.vars.not_replaced$"
|
||||
vars.test1 = "string"
|
||||
vars.test2 = 17
|
||||
vars.test3 = false
|
||||
|
|
Loading…
Reference in New Issue