Skip to content

Commit

Permalink
Work in progress
Browse files Browse the repository at this point in the history
  • Loading branch information
Fdall committed Dec 15, 2020
1 parent a4e65cd commit f23518e
Show file tree
Hide file tree
Showing 17 changed files with 408 additions and 159 deletions.
25 changes: 16 additions & 9 deletions tests/acceptance/30_generic_methods/file_copy_from_local_source.cf
Expand Up @@ -23,16 +23,19 @@ bundle agent init
{
vars:
"tmp" string => getenv("TEMP", 1024);
"source_file" string => "${tmp}/source_test";
"destination_file" string => "${tmp}/destination_test";
"destination_file_canon" string => canonify("${destination_file}");

"mode" string => "644";
"owner" string => "root";
"group" string => "0";
"source_file[0]" string => "${tmp}/source_test_0";
"destination_file[0]" string => "${tmp}/destination_test_0";
"expected_result[0]" string => "repaired";

"mode" string => "644";
"owner" string => "root";
"group" string => "0";

"indices" slist => getindices("source_file");

files:
"${source_file}"
"${source_file[0]}"
create => "true",
perms => mog("${mode}", "${owner}", "${group}");

Expand All @@ -42,8 +45,11 @@ bundle agent init

bundle agent test
{
vars:
"args${init.indices}" slist => { "${init.source_file[${init.indices}]}", "${init.destination_file[0]}" };

methods:
"ph1" usebundle => file_copy_from_local_source("${init.source_file}", "${init.destination_file}");
"ph0" usebundle => apply_gm("file_copy_from_local_source", @{args0}, "${init.expected_result[0]}", "ph0", "enforce" );
}

#######################################################
Expand All @@ -70,7 +76,8 @@ bundle agent check
expression => returnszero("${permissions_test_group}", "useshell"),
ifvarclass => canonify("file_copy_from_local_source_${init.destination_file}_reached");

"ok" expression => "permissions_test_mode_ok.permissions_test_owner_ok.permissions_test_group_ok.file_copy_from_local_source_${init.destination_file_canon}_ok.!file_copy_from_local_source_${init.destination_file_canon}_error";
"classes_ok" expression => "ph0_ok";
"ok" expression => "permissions_test_mode_ok.permissions_test_owner_ok.permissions_test_group_ok.classes_ok";

reports:
ok::
Expand Down
Expand Up @@ -23,17 +23,20 @@ bundle agent init
{
vars:
"tmp" string => getenv("TEMP", 1024);
"source_file" string => "${tmp}/source_test";
"destination_file" string => "${tmp}/destination_test";
"destination_file_canon" string => canonify("${destination_file}");
"recursion" string => "0";
"source_file[0]" string => "${tmp}/source_test_0";
"destination_file[0]" string => "${tmp}/destination_test_0";
"expected_result[0]" string => "repaired";
"recursion[0]" string => "0";

"mode" string => "644";
"owner" string => "root";
"group" string => "0";
"mode" string => "665";
"owner" string => "root";
"group" string => "0";


"indices" slist => getindices("source_file");

files:
"${source_file}"
"${source_file[0]}"
create => "true",
perms => mog("${mode}", "${owner}", "${group}");

Expand All @@ -43,8 +46,11 @@ bundle agent init

bundle agent test
{
vars:
"args${init.indices}" slist => { "${init.source_file[${init.indices}]}", "${init.destination_file[0]}", "${init.recursion[${init.indices}]}" };

methods:
"ph1" usebundle => file_copy_from_local_source_recursion("${init.source_file}", "${init.destination_file}", "${init.recursion}");
"ph0" usebundle => apply_gm("file_copy_from_local_source_recursion", @{args0}, "${init.expected_result[0]}", "ph0", "enforce" );
}

#######################################################
Expand All @@ -53,9 +59,9 @@ bundle agent check
{
vars:
"owner_id" int => getuid("${init.owner}");
"permissions_test_mode" string => "/usr/bin/test ${const.dollar}(${test_utils.file_perms} ${init.destination_file}) = \"${init.mode}\"";
"permissions_test_owner" string => "/usr/bin/test ${const.dollar}(${test_utils.file_owner} ${init.destination_file}) = \"${owner_id}\"";
"permissions_test_group" string => "/usr/bin/test ${const.dollar}(${test_utils.file_group} ${init.destination_file}) = \"${init.group}\"";
"permissions_test_mode" string => "/usr/bin/test ${const.dollar}(${test_utils.file_perms} ${init.destination_file[0]}) = \"${init.mode}\"";
"permissions_test_owner" string => "/usr/bin/test ${const.dollar}(${test_utils.file_owner} ${init.destination_file[0]}) = \"${owner_id}\"";
"permissions_test_group" string => "/usr/bin/test ${const.dollar}(${test_utils.file_group} ${init.destination_file[0]}) = \"${init.group}\"";

classes:
# By default, file_copy_from_local_source_type_recursion should create the file if it doesn't exist
Expand All @@ -71,7 +77,7 @@ bundle agent check
expression => returnszero("${permissions_test_group}", "useshell"),
ifvarclass => canonify("file_copy_from_local_source_${init.destination_file}_reached");

"ok" expression => "permissions_test_mode_ok.permissions_test_owner_ok.permissions_test_group_ok.file_copy_from_local_source_${init.destination_file_canon}_ok.!file_copy_from_local_source_${init.destination_file_canon}_error";
"ok" expression => "permissions_test_mode_ok.permissions_test_owner_ok.permissions_test_group_ok.ph0_ok";

reports:
ok::
Expand Down
@@ -0,0 +1,109 @@
#######################################################
#
# Test checking if a file can be copied from a local source
#
#######################################################

bundle common acc_path
{
vars:
"root" string => getenv("NCF_TESTS_ACCEPTANCE", 1024);
}

body common control
{
inputs => { "${acc_path.root}/default.cf.sub", "${acc_path.root}/default_ncf.cf.sub", "@{ncf_inputs.default_files}" };
bundlesequence => { configuration, default("${this.promise_filename}") };
version => "1.0";
}

#######################################################

bundle agent init
{
vars:
"tmp" string => getenv("TEMP", 1024);

## Copy a single file, create the containing folder
"source_file[0]" string => "${this.promise_filename}";
"destination_file[0]" string => "${tmp}/0/destination_test_0";
"expected_result[0]" string => "repaired";
"recursion[0]" string => "0";
"mode[0]" string => "enforce";

# Redo the #0, expect a success, recursion change is needed
# otherwise the bundle call will be skipped
"source_file[1]" string => "${this.promise_filename}";
"destination_file[1]" string => "${tmp}/0/destination_test_0";
"expected_result[1]" string => "success";
"recursion[1]" string => "inf";
"mode[1]" string => "enforce";

## Copy a folder structure, create the containing folder
"source_file[2]" string => "${this.promise_dirname}";
"destination_file[2]" string => "${tmp}/2/";
"expected_result[2]" string => "repaired";
"recursion[2]" string => "99";
"mode[2]" string => "enforce";
# Redo the #2, expect a success
# otherwise the bundle call will be skipped
"source_file[3]" string => "${this.promise_dirname}";
"destination_file[3]" string => "${tmp}/2/";
"expected_result[3]" string => "success";
"recursion[3]" string => "inf";
"mode[3]" string => "enforce";

## Try to copy a non-existing file
"source_file[4]" string => "/file/that/does/not/exist";
"destination_file[4]" string => "${tmp}/4/destination_test_4";
"expected_result[4]" string => "error";
"recursion[4]" string => "0";
"mode[4]" string => "enforce";

#### Audit
## Same file, expect success
"source_file[10]" string => "${this.promise_filename}";
"destination_file[10]" string => "${this.promise_filename}";
"expected_result[10]" string => "error";
"recursion[10]" string => "inf";
"mode[10]" string => "audit";

"indices" slist => getindices("source_file");
}

#######################################################

bundle agent test
{
vars:
"args${init.indices}" slist => { "${init.source_file[${init.indices}]}", "${init.destination_file[${init.indices}]}", "${init.recursion[${init.indices}]}" };

methods:
"ph0" usebundle => apply_gm("file_from_local_source_recursion", @{args0}, "${init.expected_result[0]}", "ph0", "${init.mode[0]}" );
"ph1" usebundle => apply_gm("file_from_local_source_recursion", @{args1}, "${init.expected_result[1]}", "ph1", "${init.mode[1]}" );
"ph2" usebundle => apply_gm("file_from_local_source_recursion", @{args2}, "${init.expected_result[2]}", "ph2", "${init.mode[2]}" );
"ph3" usebundle => apply_gm("file_from_local_source_recursion", @{args3}, "${init.expected_result[3]}", "ph3", "${init.mode[3]}" );
"ph4" usebundle => apply_gm("file_from_local_source_recursion", @{args4}, "${init.expected_result[4]}", "ph4", "${init.mode[4]}" );

"ph10" usebundle => apply_gm("file_from_local_source_recursion", @{args10}, "${init.expected_result[10]}", "ph10", "${init.mode[10]}" );
}

#######################################################

bundle agent check
{
vars:
"hash_source[${init.indices}]" string => execresult("${ncf_paths.path[find]} ${init.source_file[${init.indices}]} -type f -exec md5sum '{}' +| ${ncf_paths.path[cut]} -d' ' -f1 | md5sum", "useshell");
"hash_destination[${init.indices}]" string => execresult("${ncf_paths.path[find]} ${init.destination_file[${init.indices}]} -type f -exec md5sum '{}' +| ${ncf_paths.path[cut]} -d' ' -f1 | md5sum", "useshell");
classes:
"hash_ok_${init.indices}" expression => strcmp("${hash_source_[${init_indices}]}", "${hash_destination_[${init_indices}]}");
"copy_not_ok" not => "hash_ok_${init.indices}";

"ok" expression => "copy_not_ok.ph0_ok.ph1_ok.ph2_ok.ph3_ok.ph4_ok.ph10_ok";

reports:
ok::
"$(this.promise_filename) Pass";
!ok::
"$(this.promise_filename) FAIL";
}
100 changes: 0 additions & 100 deletions tests/acceptance/30_generic_methods/file_from_template_jinja2.cf

This file was deleted.

0 comments on commit f23518e

Please sign in to comment.