Skip to content

Commit

Permalink
Require tests to explicitly include all fact values
Browse files Browse the repository at this point in the history
This mostly impacts anywhere the operation expects the fact to return
`None`, which was the default before this change. Now requires each test
to explicitly define the fact return value or an exception will be raised.

As can be seen in the mass update of test files there were a number of
invalid test facts defined that relied on this bahavior, moving to an
explicit definition is a significant improvement.
  • Loading branch information
Fizzadar committed Nov 16, 2024
1 parent 63ff580 commit e5b2290
Show file tree
Hide file tree
Showing 133 changed files with 250 additions and 161 deletions.
2 changes: 1 addition & 1 deletion tests/operations/apt.deb/add.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"path=_tempfile_": ""
},
"deb.DebPackage": {
"name=_tempfile_": {
"package=_tempfile_": {
"name": "test",
"version": 0
}
Expand Down
2 changes: 1 addition & 1 deletion tests/operations/apt.deb/download_add.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"path=_tempfile_": null
},
"deb.DebPackage": {
"name=_tempfile_": null
"package=_tempfile_": null
},
"deb.DebPackages": {},
"server.Which": {
Expand Down
2 changes: 1 addition & 1 deletion tests/operations/apt.deb/remove_no_exist.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"path=_tempfile_": ""
},
"deb.DebPackage": {
"name=_tempfile_": {
"package=_tempfile_": {
"name": "test",
"version": 0
}
Expand Down
2 changes: 1 addition & 1 deletion tests/operations/apt.dist_upgrade/dist_upgrade.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
],
"facts": {
"apt.SimulateOperationWillChange": {

"command=dist-upgrade": {}
}
}
}
4 changes: 3 additions & 1 deletion tests/operations/apt.packages/update_upgrade.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
},
"facts": {
"deb.DebPackages": {},
"apt.SimulateOperationWillChange": {}
"apt.SimulateOperationWillChange": {
"command=upgrade": {}
}
},
"commands": [
"apt-get update",
Expand Down
2 changes: 1 addition & 1 deletion tests/operations/apt.repo/add.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"facts": {
"apt.AptSources": [],
"files.FindInFile": {
"path=/etc/apt/sources.list, pattern=^.*deb http://archive\\.canonical\\.com/ubuntu hardy partner.*$, interpolate_variables=False": []
"interpolate_variables=False, path=/etc/apt/sources.list, pattern=^.*deb http://archive\\.canonical\\.com/ubuntu hardy partner.*$": []
}
},
"commands": [
Expand Down
2 changes: 1 addition & 1 deletion tests/operations/apt.repo/add_filename.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"facts": {
"apt.AptSources": [],
"files.FindInFile": {
"path=/etc/apt/sources.list.d/somefile.list, pattern=^.*deb http://archive\\.canonical\\.com/ubuntu hardy partner.*$, interpolate_variables=False": []
"interpolate_variables=False, path=/etc/apt/sources.list.d/somefile.list, pattern=^.*deb http://archive\\.canonical\\.com/ubuntu hardy partner.*$": []
}
},
"commands": [
Expand Down
10 changes: 6 additions & 4 deletions tests/operations/apt.upgrade/upgrade.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@
"args": [],
"facts": {
"apt.SimulateOperationWillChange": {
"upgraded": 15,
"newly_installed": 0,
"removed": 0,
"not_upgraded": 0
"command=upgrade": {
"upgraded": 15,
"newly_installed": 0,
"removed": 0,
"not_upgraded": 0
}
}
},
"commands": [
Expand Down
2 changes: 1 addition & 1 deletion tests/operations/apt.upgrade/upgrade_autoremove.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
],
"facts": {
"apt.SimulateOperationWillChange": {

"command=upgrade --autoremove": {}
}
}
}
2 changes: 1 addition & 1 deletion tests/operations/bsdinit.service/disabled.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"nginx": true
},
"files.FindInFile": {
"path=/etc/rc.conf.local, pattern=^nginx_enable=.*$, interpolate_variables=False": [
"interpolate_variables=False, path=/etc/rc.conf.local, pattern=^nginx_enable=.*$": [
"nginx_enable=\"YES\""
]
}
Expand Down
4 changes: 2 additions & 2 deletions tests/operations/bsdinit.service/enabled.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
"nginx": true
},
"files.FindInFile": {
"path=/etc/rc.conf.local, pattern=^nginx_enable=.*$, interpolate_variables=False": [],
"path=/etc/rc.conf.local, pattern=^.*nginx_enable=\"YES\".*$, interpolate_variables=False": []
"interpolate_variables=False, path=/etc/rc.conf.local, pattern=^nginx_enable=.*$": [],
"interpolate_variables=False, path=/etc/rc.conf.local, pattern=^nginx_enable=\"YES\"$": []
}
},
"commands": [
Expand Down
3 changes: 2 additions & 1 deletion tests/operations/dnf.repo/add.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
"path=/etc/yum.repos.d/somerepo.repo": {}
},
"files.Directory": {
"path=/etc/yum.repos.d": true
"path=/etc/yum.repos.d": true,
"path=/etc/yum.repos.d/somerepo.repo": null
}
},
"commands": [[
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
},
"facts": {
"files.Block": {
"path=/home/someone/something, marker=None, begin=None, end=None": ["previously was something else"]
"begin=None, end=None, marker=None, path=/home/someone/something": ["previously was something else"]
}
},
"commands": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
},
"facts": {
"files.Block": {
"path=/home/someone/something, marker=None, begin=None, end=None": ["previously was something else"]
"begin=None, end=None, marker=None, path=/home/someone/something": ["previously was something else"]
}
},
"commands": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
},
"facts": {
"files.Block": {
"path=/home/someone/something, marker=None, begin=None, end=None": ["the one true string"]
"begin=None, end=None, marker=None, path=/home/someone/something": ["the one true string"]
}
},
"commands": [],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
},
"facts": {
"files.Block": {
"path=/home/someone/something, marker=None, begin=None, end=None": null
"begin=None, end=None, marker=None, path=/home/someone/something": null
}
},
"exception": {
Expand Down
2 changes: 1 addition & 1 deletion tests/operations/files.block/add_no_content_provided.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"args": ["/home/someone/something"],
"facts": {
"files.Block": {
"path=/home/someone/something, marker=None, begin=None, end=None": null
"begin=None, end=None, marker=None, path=/home/someone/something": null
}
},
"exception": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
},
"facts": {
"files.Block": {
"path=/home/someone/something, marker=None, begin=None, end=None": null
"begin=None, end=None, marker=None, path=/home/someone/something": null
}
},
"commands": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
},
"facts": {
"files.Block": {
"path=/home/someone/something, marker=None, begin=None, end=None": []
"begin=None, end=None, marker=None, path=/home/someone/something": []
}
},
"commands": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
},
"facts": {
"files.Block": {
"path=/home/someone/something, marker=None, begin=None, end=None": []
"begin=None, end=None, marker=None, path=/home/someone/something": []
}
},
"commands": [
Expand Down
2 changes: 1 addition & 1 deletion tests/operations/files.block/add_no_existing_file.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
},
"facts": {
"files.Block": {
"path=/home/someone/something, marker=None, begin=None, end=None": null
"begin=None, end=None, marker=None, path=/home/someone/something": null
}
},
"commands": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
},
"facts": {
"files.Block": {
"path=/home/someone/something, marker=None, begin=None, end=None": null
"begin=None, end=None, marker=None, path=/home/someone/something": null
}
},
"exception": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
},
"facts": {
"files.Block": {
"path=/home/someone/something, marker=None, begin=None, end=None": ["some existing content"]
"begin=None, end=None, marker=None, path=/home/someone/something": ["some existing content"]
}
},
"commands": [
Expand Down
2 changes: 1 addition & 1 deletion tests/operations/files.block/remove_existing_block.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
},
"facts": {
"files.Block": {
"path=/home/someone/something, marker=None, begin=None, end=None": ["existing content"]
"begin=None, end=None, marker=None, path=/home/someone/something": ["existing content"]
}
},
"commands": [
Expand Down
2 changes: 1 addition & 1 deletion tests/operations/files.block/remove_no_existing_block.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"kwargs": {"present": false},
"facts": {
"files.Block": {
"path=/home/someone/something, marker=None, begin=None, end=None": []
"begin=None, end=None, marker=None, path=/home/someone/something": []
}
},
"commands": [],
Expand Down
2 changes: 1 addition & 1 deletion tests/operations/files.block/remove_no_file.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"kwargs": {"present": false},
"facts": {
"files.Block": {
"path=/home/someone/something, marker=None, begin=None, end=None": null
"begin=None, end=None, marker=None, path=/home/someone/something": null
}
},
"commands": [],
Expand Down
2 changes: 1 addition & 1 deletion tests/operations/files.directory/add_with_spaces.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
},
"facts": {
"files.Directory": {
"path=testdir": null
"path=test dir": null
}
},
"commands": [
Expand Down
2 changes: 1 addition & 1 deletion tests/operations/files.line/add.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"args": ["somefile", "match_line"],
"facts": {
"files.FindInFile": {
"path=somefile, pattern=^.*match_line.*$, interpolate_variables=False": []
"interpolate_variables=False, path=somefile, pattern=^.*match_line.*$": []
}
},
"commands": [
Expand Down
2 changes: 1 addition & 1 deletion tests/operations/files.line/add_backup.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
},
"facts": {
"files.FindInFile": {
"path=somefile, pattern=^.*match_line.*$, interpolate_variables=False": []
"interpolate_variables=False, path=somefile, pattern=^.*match_line.*$": []
}
},
"commands": [
Expand Down
2 changes: 1 addition & 1 deletion tests/operations/files.line/add_existing.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
},
"facts": {
"files.FindInFile": {
"path=somefile, pattern=^.*match_line.*$, interpolate_variables=False": ["replace_line"]
"interpolate_variables=False, path=somefile, pattern=^.*match_line.*$": ["replace_line"]
}
},
"commands": [],
Expand Down
2 changes: 1 addition & 1 deletion tests/operations/files.line/add_replace.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"facts": {
"files.FindInFile": {
"interpolate_variables=False, path=somefile, pattern=^.*match_line.*$": [],
"interpolate_variables=False, path=somefile, pattern=^.*replace_line.*$": []
"interpolate_variables=False, path=somefile, pattern=^replace_line$": []
}
},
"commands": [
Expand Down
4 changes: 2 additions & 2 deletions tests/operations/files.line/add_replace_noop.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
},
"facts": {
"files.FindInFile": {
"path=somefile, pattern=^.*match_line.*$, interpolate_variables=False": [],
"path=somefile, pattern=^replace_line$, interpolate_variables=False": ["replace_line"]
"interpolate_variables=False, path=somefile, pattern=^.*match_line.*$": [],
"interpolate_variables=False, path=somefile, pattern=^replace_line$": ["replace_line"]
}
},
"commands": [],
Expand Down
2 changes: 1 addition & 1 deletion tests/operations/files.line/edit.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
},
"facts": {
"files.FindInFile": {
"path=somefile, pattern=^.*match_line.*$, interpolate_variables=False": [
"interpolate_variables=False, path=somefile, pattern=^.*match_line.*$": [
"match_line"
]
}
Expand Down
2 changes: 1 addition & 1 deletion tests/operations/files.line/edit_backup.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
},
"facts": {
"files.FindInFile": {
"path=somefile, pattern=^.*match_line.*$, interpolate_variables=False": [
"interpolate_variables=False, path=somefile, pattern=^.*match_line.*$": [
"match_line"
]
}
Expand Down
2 changes: 1 addition & 1 deletion tests/operations/files.line/pathlib_edit.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
},
"facts": {
"files.FindInFile": {
"path=somefile, pattern=^.*match_line.*$, interpolate_variables=False": [
"interpolate_variables=False, path=somefile, pattern=^.*match_line.*$": [
"match_line"
]
}
Expand Down
4 changes: 3 additions & 1 deletion tests/operations/files.put/copy_local_permissions.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,11 @@
},
"facts": {
"files.File": {
"path=/home/some\\ file.txt": null
"path=/somefile.txt": null,
"path=/somefile.txt/somefile.txt": null
},
"files.Directory": {
"path=/somefile.txt": false,
"path=/": true
}
},
Expand Down
3 changes: 2 additions & 1 deletion tests/operations/files.put/create_directory.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@
"path=/home/somefile.txt": null
},
"files.Directory": {
"path=/home": null
"path=/home": null,
"path=/home/somefile.txt": null
}
},
"commands": [
Expand Down
3 changes: 2 additions & 1 deletion tests/operations/files.put/no_remote.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@
"path=/home/somefile.txt": null
},
"files.Directory": {
"path=/home": true
"path=/home": true,
"path=/home/somefile.txt": null
}
},
"commands": [
Expand Down
5 changes: 3 additions & 2 deletions tests/operations/files.put/path_with_spaces.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@
},
"facts": {
"files.File": {
"path=/home/some\\ file.txt": null
"path=/home/some file.txt": null
},
"files.Directory": {
"path=/home": true
"path=/home": true,
"path=/home/some file.txt": false
}
},
"commands": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
"path=/home/some\\ file.txt": null
},
"files.Directory": {
"path=/home": true
"path=/home": true,
"path=/home/some\\ file.txt": false
}
},
"commands": [
Expand Down
Loading

0 comments on commit e5b2290

Please sign in to comment.