Skip to content

Commit

Permalink
Merge pull request #3689 from nickanderson/ENT-4681/master
Browse files Browse the repository at this point in the history
ENT-4681: Test proper scoping of classes defined from non-default namespace
  • Loading branch information
nickanderson authored Jul 2, 2019
2 parents 52e5801 + 2d17459 commit 3c4d046
Show file tree
Hide file tree
Showing 4 changed files with 316 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
#!/var/cfengine/bin/cf-agent -f-
body common control
{
inputs => { "../../default.cf.sub" };
bundlesequence => {
default("$(this.promise_filename)") };
version => "1.0";
}
body file control { namespace => "test"; }
bundle agent example
{
classes:
"TRIGGERED"
expression => "any",
scope => "bundle"; # Bundle scoped classes are NOT visible from other bundles
}
body file control { namespace => "default"; }
bundle agent test
{
meta:
"description" -> {"ENT-4681" }
string => "Test that bundle scoped classes defined from namespaced
agent bundles are properly scoped. Specifically from the default
namespace.";

"test_soft_fail"
string => "any",
meta => { "ENT-4681" };

methods:
"test:example";
}
bundle agent check
{
classes:
# Expectation, default:TRIGGERED is NOT defined
"default_TRIGGERED_OK"
expression => "!default:TRIGGERED";

# Expectation, test:TRIGGERED is NOT defined (not visable since it's a bundle scoped class)
"namespaced_TRIGGERED_OK"
expression => "!test:TRIGGERED";

# Expectation, TRIGGERED is NOT defined, we are now in the default namespace, the TRIGGERED class was defined in the test namespace with a bundle scope
"TRIGGERED_OK"
expression => "!TRIGGERED";


"pass" and => {
"default_TRIGGERED_OK",
"namespaced_TRIGGERED_OK",
"TRIGGERED_OK",
};
reports:
pass::
"Pass $(this.promise_filename)";
!pass::
"FAIL $(this.promise_filename)";
!default_TRIGGERED_OK::
"Expected 'default:TRIGGERED' to not be seen as defined, but expression '!default:TRIGGERED' resulted in true";
!namespaced_TRIGGERED_OK::
"Expected 'test:TRIGGERED' to NOT be seen as defined, but expression '!test:TRIGGERED' resulted in false";
!TRIGGERED_OK::
"Expected 'TRIGGERED' to NOT be seen as defined, but expression 'TRIGGERED' resulted in true even without specify the test namespace";

}
bundle agent __main__
{

methods:
"test:example";
"check";
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
#!/var/cfengine/bin/cf-agent -f-
body common control
{
inputs => { "../../default.cf.sub" };
bundlesequence => {
default("$(this.promise_filename)") };
version => "1.0";
}
body file control { namespace => "test"; }
bundle agent example
{
classes:
"TRIGGERED"
expression => "any",
scope => "bundle"; # Namespace scoped classes are visible from other bundles
}
bundle agent check
{
classes:
# Expectation, default:TRIGGERED is NOT defined
"default_TRIGGERED_OK"
expression => "!default:TRIGGERED";

# Expectation, test:TRIGGERED is NOT defined (not visable since it's a bundle scoped class)
"namespaced_TRIGGERED_OK"
expression => "!test:TRIGGERED";

# Expectation, TRIGGERED is NOT defined, we are now in the test namespace where the TRIGGERED class was defined, but it was bundle scoped, so not visable from another bundle
"TRIGGERED_OK"
expression => "!TRIGGERED";


"pass" and => {
"default_TRIGGERED_OK",
"namespaced_TRIGGERED_OK",
"TRIGGERED_OK",
};
reports:
pass::
"Pass $(this.promise_filename)";
!pass::
"FAIL $(this.promise_filename)";
!default_TRIGGERED_OK::
"Expected 'default:TRIGGERED' to not be seen as defined, but expression '!default:TRIGGERED' resulted in true";
!namespaced_TRIGGERED_OK::
"Expected 'test:TRIGGERED' to NOT be seen as defined, but expression '!test:TRIGGERED' resulted in false";
!TRIGGERED_OK::
"Expected 'TRIGGERED' to NOT be seen as defined, but expression '!TRIGGERED' resulted in false";

}
body file control { namespace => "default"; }
bundle agent test
{
meta:
"description" -> {"ENT-4681" }

string => "Test that bundle scoped classes defined from namespaced
agent bundles are properly scoped. Specifically from the perspective of
the non-default namespace itself.";


"test_soft_fail"
string => "any",
meta => { "ENT-4681" };

methods:
"test:example";
}
bundle agent check
{
methods:
"test:check";
}
bundle agent __main__
{

methods:
"test";
"check";
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
#!/var/cfengine/bin/cf-agent -f-
body common control
{
inputs => { "../../default.cf.sub" };
bundlesequence => {
default("$(this.promise_filename)") };
version => "1.0";
}
body file control { namespace => "test"; }
bundle agent example
{
classes:
"TRIGGERED"
expression => "any",
scope => "namespace"; # Namespace scoped classes are visible from other bundles

reports:
TRIGGERED::
"TRIGGERED is defined within $(this.namespace).$(this.bundle)";

default:TRIGGERED::
"default:TRIGGERED is defined within $(this.namespace).$(this.bundle)";

test:TRIGGERED::
"$(this.namespace):TRIGGERED is defined within $(this.namespace).$(this.bundle)";
}
body file control { namespace => "default"; }
bundle agent test
{
meta:
"description" -> {"ENT-4681" }
string => "Test that namespace scoped classes defined from namespaced
agent bundles are properly scoped. Specifically from the default
namespace.";

"test_soft_fail"
string => "any",
meta => { "ENT-4681" };

methods:
"test:example";
}
bundle agent check
{
classes:
# Expectation, default:TRIGGERED is NOT defined
"default_TRIGGERED_OK"
expression => "!default:TRIGGERED";

# Expectation, test:TRIGGERED is defined (visable since it's a namespace scoped class)
"namespaced_TRIGGERED_OK"
expression => "test:TRIGGERED";

# Expectation, TRIGGERED is NOT defined, we are now in the default namespace, the TRIGGERED class was defined in the test namespace and should not be seen without explicitly using it's namespace
"TRIGGERED_OK"
expression => "!TRIGGERED";


"pass" and => {
"default_TRIGGERED_OK",
"namespaced_TRIGGERED_OK",
"TRIGGERED_OK",
};
reports:
pass::
"Pass $(this.promise_filename)";
!pass::
"FAIL $(this.promise_filename)";
!default_TRIGGERED_OK::
"Expected 'default:TRIGGERED' to not be seen as defined, but expression '!default:TRIGGERED' resulted in true";
!namespaced_TRIGGERED_OK::
"Expected 'test:TRIGGERED' to be seen as defined, but expression 'test:TRIGGERED' resulted in false";
!TRIGGERED_OK::
"Expected 'TRIGGERED' to NOT be seen as defined, but expression 'TRIGGERED' resulted in true even without specify the test namespace";

}
bundle agent __main__
{

methods:
"test:example";
"check";
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
#!/var/cfengine/bin/cf-agent -f-
body common control
{
inputs => { "../../default.cf.sub" };
bundlesequence => {
default("$(this.promise_filename)") };
version => "1.0";
}
body file control { namespace => "test"; }
bundle agent example
{
classes:
"TRIGGERED"
expression => "any",
scope => "namespace"; # Namespace scoped classes are visible from other bundles
}
bundle agent check
{
classes:
# Expectation, default:TRIGGERED is NOT defined
"default_TRIGGERED_OK"
expression => "!default:TRIGGERED";

# Expectation, test:TRIGGERED is defined (visable since it's a namespace scoped class)
"namespaced_TRIGGERED_OK"
expression => "test:TRIGGERED";

# Expectation, TRIGGERED is defined, we are now in the test namespace where the TRIGGERED class was defined. We should be able to reference classes defined in our current namespace without being explicit
"TRIGGERED_OK"
expression => "TRIGGERED";


"pass" and => {
"default_TRIGGERED_OK",
"namespaced_TRIGGERED_OK",
"TRIGGERED_OK",
};
reports:
pass::
"Pass $(this.promise_filename)";
!pass::
"FAIL $(this.promise_filename)";
!default_TRIGGERED_OK::
"Expected 'default:TRIGGERED' to not be seen as defined, but expression '!default:TRIGGERED' resulted in true";
!namespaced_TRIGGERED_OK::
"Expected 'test:TRIGGERED' to be seen as defined, but expression 'test:TRIGGERED' resulted in false";
!TRIGGERED_OK::
"Expected 'TRIGGERED' to be seen as defined, but expression 'TRIGGERED' resulted in false";

}
body file control { namespace => "default"; }
bundle agent test
{
meta:
"description" -> {"ENT-4681" }

string => "Test that namespace scoped classes defined from namespaced
agent bundles are properly scoped. Specifically from the perspective of
the non-default namespace itself.";


"test_soft_fail"
string => "any",
meta => { "ENT-4681" };

methods:
"test:example";
}
bundle agent check
{
methods:
"test:check";
}
bundle agent __main__
{

methods:
"test";
"check";
}

0 comments on commit 3c4d046

Please sign in to comment.