Skip to content

Commit

Permalink
Expand files module tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
Fizzadar committed Jun 13, 2019
1 parent 5b468d2 commit dd6c75d
Show file tree
Hide file tree
Showing 7 changed files with 85 additions and 5 deletions.
17 changes: 17 additions & 0 deletions tests/operations/files.line/add_no_exist.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"args": ["somefile", "match_line"],
"kwargs": {
"replace": "replace_line",
"flags": "abc"
},
"facts": {
"find_in_file": {
"somefile": {
"^.*match_line.*$": null
}
}
},
"commands": [
"# If the file now exists\n if [ -f \"somefile\" ]; then\n # Grep for the line, sed if matches\n (grep \"^.*match_line.*$\" \"somefile\" && sed -i=\"\" \"s/^.*match_line.*$/replace_line/abc\" somefile) || # Else echo\n echo \"replace_line\" >> somefile\n\n # No file, just echo\n else\n echo \"replace_line\" >> somefile\n fi"
]
}
19 changes: 19 additions & 0 deletions tests/operations/files.line/edit.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"args": ["somefile", "match_line"],
"kwargs": {
"replace": "replace_line",
"flags": "abc"
},
"facts": {
"find_in_file": {
"somefile": {
"^.*match_line.*$": [
"match_line"
]
}
}
},
"commands": [
"sed -i=\"\" \"s/^.*match_line.*$/replace_line/abc\" somefile"
]
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"args": ["somefile.txt", "/home/somefile.txt"],
"kwargs": {
"user": "testuser",
"group": "testgroup",
"user": "another-testuser",
"group": "another-testgroup",
"mode": 644
},
"files": ["somefile.txt"],
Expand All @@ -19,6 +19,7 @@
}
},
"commands": [
"chmod 644 /home/somefile.txt"
"chmod 644 /home/somefile.txt",
"chown another-testuser:another-testgroup /home/somefile.txt"
]
}
7 changes: 7 additions & 0 deletions tests/operations/files.put/no_local.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"args": ["somefile.txt", "/home/somefile.txt"],
"exception": {
"names": ["OSError", "IOError"],
"message": "No such file: /somefile.txt"
}
}
4 changes: 2 additions & 2 deletions tests/operations/files.sync/sync_delete.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
"args": ["/somedir", "/home/somedir"],
"args": ["/somedir/", "/home/somedir"],
"kwargs": {
"delete": true
},
"directories": {
"/somedir": ["somefile.txt", "anotherfile.txt"]
"/somedir/": ["somefile.txt", "anotherfile.txt"]
},
"facts": {
"directory": {
Expand Down
21 changes: 21 additions & 0 deletions tests/operations/files.sync/sync_exclude.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"args": ["/somedir/", "/home/somedir"],
"kwargs": {
"exclude": "somefile.txt",
"exclude_dir": "dir"
},
"directories": {
"/somedir/": ["somefile.txt", "anotherfile.txt"]
},
"facts": {
"directory": {
"/home/somedir": null
},
"find_files": {
"/home/somedir": null
}
},
"commands": [
"mkdir -p /home/somedir"
]
}
15 changes: 15 additions & 0 deletions tests/operations/files.sync/sync_no_local_exist.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"args": ["/i-do-not-exist", "/home/somedir"],
"facts": {
"directory": {
"/home/somedir": null
},
"find_files": {
"/home/somedir": null
}
},
"exception": {
"names": ["OSError", "IOError"],
"message": "No such directory: /i-do-not-exist/"
}
}

0 comments on commit dd6c75d

Please sign in to comment.