-
Notifications
You must be signed in to change notification settings - Fork 66
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #616 from Hornwitser/fix-mod-settings-types
Handle bad mod setting types
- Loading branch information
Showing
9 changed files
with
203 additions
and
12 deletions.
There are no files selected for viewing
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
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
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,35 @@ | ||
# Manual Tests | ||
|
||
This folder contains files used for performing manual tests that are non-trivial to automate. | ||
|
||
## Setup test mod | ||
|
||
Run `node packages/lib/dist/node/build_mod.js --source-dir test/manual/test_mod/ --output-dir mods/` to create the test mod. | ||
|
||
## Test handling of bad setting values | ||
|
||
1. Create a ModPack with missmatched values with `node test/manual/test_settings_mod_pack.js` and import it. | ||
2. Run a data export on an instance with the mod pack assigned, the values will get coerced to the correct types. | ||
3. Use ctl to set the settings back to their wrong values: | ||
|
||
```bash | ||
SETTING_TYPES=(bool-setting int-setting double-setting string-setting color-setting) | ||
VALUE_TYPES=(bool int double string color missing) | ||
VALUES=( | ||
--bool-setting false | ||
--int-setting 1 | ||
--double-setting 0.5 | ||
--string-setting str | ||
--color-setting '{"r":0,"g":1,"b":0,"a":1}' | ||
--remove-setting | ||
) | ||
node packages/ctl mod-pack edit test-settings $( | ||
for TYPE in "${SETTING_TYPES[@]}" ; do | ||
for (( I = 0; I < ${#VALUE_TYPES[@]}; I++ )); do | ||
printf "%s startup %s-with-%s-value %s " ${VALUES[((I * 2))]} $TYPE ${VALUE_TYPES[I]} ${VALUES[((I * 2 + 1))]} | ||
done | ||
done | ||
) | ||
``` | ||
|
||
4. Verify that the Web UI gracefully handles all combinations of wrong settings types. |
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,7 @@ | ||
{ | ||
"name": "test_mod", | ||
"version": "0.0.0", | ||
"title": "test_mod", | ||
"author": "", | ||
"factorio_version": "1.1" | ||
} |
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,22 @@ | ||
local settings = { | ||
["bool-setting"] = true, | ||
["int-setting"] = 123, | ||
["double-setting"] = 1234.5, | ||
["string-setting"] = "string", | ||
["color-setting"] = { r = 1, g = 0, b = 1, a = 1 }, | ||
} | ||
|
||
local possible_values = { "missing", "bool", "int", "double", "string", "color" } | ||
|
||
for name, default_value in pairs(settings) do | ||
for _, value in ipairs(possible_values) do | ||
data:extend({ | ||
{ | ||
type = name, | ||
name = name .. "-with-" .. value .. "-value", | ||
setting_type = "startup", | ||
default_value = default_value, | ||
} | ||
}) | ||
end | ||
end |
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,28 @@ | ||
"use strict"; | ||
const { ModPack } = require("@clusterio/lib"); | ||
|
||
const pack = new ModPack(); | ||
pack.name = "test-settings"; | ||
pack.mods.set("test_mod", { name: "test_mod", enabled: true, version: "0.0.0" }); | ||
const settingTypes = [ | ||
"bool-setting", | ||
"int-setting", | ||
"double-setting", | ||
"string-setting", | ||
"color-setting", | ||
]; | ||
const settingValues = { | ||
"bool": false, | ||
"int": 1, | ||
"double": 0.5, | ||
"string": "str", | ||
"color": { r: 0, g: 1, b: 0, a: 1 }, | ||
// "missing": | ||
}; | ||
for (const type of settingTypes) { | ||
for (const [valueType, value] of Object.entries(settingValues)) { | ||
pack.settings.startup.set(`${type}-with-${valueType}-value`, { value }); | ||
} | ||
} | ||
/* eslint-disable no-console */ | ||
console.log(pack.toModPackString()); |