-
Notifications
You must be signed in to change notification settings - Fork 38
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
refs #4268: ensure section in block #21
Merged
Kegeruneku
merged 1 commit into
Normation:master
from
ncharles:dev_4268/file_ensure_block_in_section
Dec 16, 2013
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
76 changes: 76 additions & 0 deletions
76
tests/acceptance/30_generic_methods/file_ensure_block_in_section.cf
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
####################################################### | ||
# | ||
# Test checking if a text block is present in a file | ||
# | ||
####################################################### | ||
|
||
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 => { default("$#this.promise_filename}") }; | ||
version => "1.0"; | ||
} | ||
|
||
####################################################### | ||
|
||
bundle agent init | ||
{ | ||
vars: | ||
"tmp" string => getenv("TEMP", 1024); | ||
"reference_file" string => "${tmp}/reference"; | ||
"file" string => "${tmp}/test"; | ||
"file_canon" string => canonify("${file}"); | ||
"section_start" string => "<Directory section_test>"; | ||
"section_end" string => "</Directory>"; | ||
"block_to_add" string => "This is a test block | ||
with multiple lines | ||
to check content in section"; | ||
|
||
"reference_content" string => "${section_start} | ||
${block_to_add} | ||
${section_end}"; | ||
|
||
commands: | ||
"/bin/echo" | ||
args => "\"${reference_content}\" > \"${reference_file}\"", | ||
contain => in_shell; | ||
} | ||
|
||
####################################################### | ||
|
||
bundle agent test | ||
{ | ||
methods: | ||
"ph1" usebundle => file_ensure_block_in_section("${init.file}", "${init.section_start}", "${init.section_end}", "${init.block_to_add}"); | ||
} | ||
|
||
####################################################### | ||
|
||
bundle agent check | ||
{ | ||
vars: | ||
"line_exists_test" string => "/usr/bin/diff \"${init.reference_file}\" \"${init.file}\""; | ||
|
||
classes: | ||
# By default, file_ensure_block_in_section should create the file if it doesn't exist | ||
"file_exists" expression => fileexists("${init.file}"); | ||
"block_exists" expression => returnszero("${line_exists_test}", "noshell"); | ||
|
||
"ok" expression => "file_exists.block_exists.file_ensure_block_in_section_${init.file_canon}_ok.!file_ensure_block_in_section_${init.file_canon}_error"; | ||
|
||
reports: | ||
ok:: | ||
"$(this.promise_filename) Pass"; | ||
!ok:: | ||
"$(this.promise_filename) FAIL"; | ||
!file_exists:: | ||
"fileexists returns false for file ${init.file}"; | ||
!block_exists:: | ||
"diff command doesn't return 0 for command: ${line_exists_test}"; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
##################################################################################### | ||
# Copyright 2013 Normation SAS | ||
##################################################################################### | ||
# | ||
# This program is free software: you can redistribute it and/or modify | ||
# it under the terms of the GNU General Public License as published by | ||
# the Free Software Foundation, Version 3. | ||
# | ||
# This program is distributed in the hope that it will be useful, | ||
# but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
# GNU General Public License for more details. | ||
# | ||
# You should have received a copy of the GNU General Public License | ||
# along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
# | ||
##################################################################################### | ||
|
||
# @name File ensure block in section | ||
# @description This is a bundle to ensure that a section contain exactly a text block | ||
# | ||
# @parameter file File name to edit | ||
# @parameter section_start Start of the section | ||
# @parameter section_end End of the section | ||
# @parameter block Block representing the content of the section | ||
# | ||
# @class_prefix file_ensure_block_in_section | ||
# @class_parameter file | ||
# | ||
# This bundle will define a class file_ensure_block_in_section_${file}_{kept,repaired,error,ok,reached} | ||
bundle agent file_ensure_block_in_section(file, section_start, section_end, block) | ||
{ | ||
vars: | ||
"class_prefix" string => canonify("file_ensure_block_in_section_${file}"); | ||
|
||
files: | ||
"${file}" | ||
create => "true", | ||
edit_line => ncf_ensure_section_content("${section_start}", "${section_end}", "${block}"), | ||
edit_defaults => no_backup, | ||
classes => classes_generic("${class_prefix}"); | ||
|
||
methods: | ||
"report" | ||
usebundle => _logger("Insert text block ${block} into ${file}", "${class_prefix}"); | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Somehow, this fails. It doesn't find the files
But in the workdir, I do have these files. Any clue ?