@@ -45,72 +45,6 @@ local function init_ami_test(testDir, configPath, options)
4545 error_called = false
4646end
4747
48- local function add_modify_and_show_test (test , mode , file , set_path , value )
49- test [" modify and show: " .. tostring (mode or " --set" ) .. " , " .. tostring (file ) .. " , " .. tostring (set_path ) .. " , " .. tostring (value )] = function ()
50- local test_dir = " tests/tmp/ami_test_modify"
51- init_ami_test (test_dir , " tests/app/configs/ami_test_app@latest.hjson" , { cleanupTestDir = true })
52-
53- os .chdir (default_cwd )
54- if type (file ) == " string" then
55- local file = path .combine (test_dir , file )
56- if not fs .exists (file ) then
57- fs .write_file (file , " {}" )
58- end
59- end
60-
61- local cwd = os .cwd () or " ."
62- local args = { " --log-level=error" , " --path=" .. test_dir , " modify" , set_path , value }
63- if type (file ) == " string" then
64- table.insert (args , 4 , " --file=" .. file )
65- end
66- if type (mode ) == " string" then
67- table.insert (args , 4 , " --" .. mode )
68- end
69- ami (table.unpack (args ))
70- os .chdir (cwd ) -- restore cwd
71- local original_print = print
72- local printed = " "
73- print = function (...)
74- for _ , v in ipairs ({... }) do
75- printed = printed .. tostring (v ) .. " \t "
76- end
77- printed = printed .. " \n "
78- end
79-
80- local show_args = { " --log-level=error" , " --path=" .. test_dir , " show" }
81- if type (file ) == " string" then
82- table.insert (show_args , 4 , " --file=" .. file )
83- end
84- ami (table.unpack (show_args ))
85- print = original_print
86- os .chdir (default_cwd )
87- test .assert (not error_called )
88-
89- local value_as_string = type (value ) == " string" and value or hjson .stringify (value , { indent = false , sort_keys = true , invalid_objects_as_type = true })
90- if mode == " unset" or mode == " remove" then
91- test .assert (printed :match (" null" ) or printed :match (value_as_string ) == nil , " Unexpected value '" .. tostring (value ) .. " ' found in output: " .. printed )
92- else
93- test .assert (printed :match (value_as_string ) ~= nil , " Expected value '" .. tostring (value ) .. " ' not found in output: " .. printed )
94- end
95- end
96- end
97-
98- add_modify_and_show_test (test , " set" , nil , " test" , " 123" )
99- add_modify_and_show_test (test , nil , nil , " test.new_value" , " 123" )
100- add_modify_and_show_test (test , " unset" , nil , " test.new_value" , nil )
101- add_modify_and_show_test (test , " add" , nil , " test" , " item3" )
102- add_modify_and_show_test (test , " add" , nil , " test.list" , " item4" )
103- add_modify_and_show_test (test , " remove" , nil , " test.list" , " item4" )
104- add_modify_and_show_test (test , " remove" , nil , " configuration.TEST_CONFIGURATION" , " bool2" )
105-
106- add_modify_and_show_test (test , " set" , " test.hjson" , " test" , " 123" )
107- add_modify_and_show_test (test , nil , " test.hjson" , " test.new_value" , " 123" )
108- add_modify_and_show_test (test , " unset" , " test.hjson" , " test.new_value" , nil )
109- add_modify_and_show_test (test , " add" , " test.hjson" , " test" , " item3" )
110- add_modify_and_show_test (test , " add" , " test.hjson" , " test.list" , " item4" )
111- add_modify_and_show_test (test , " remove" , " test.hjson" , " test.list" , " item4" )
112- add_modify_and_show_test (test , " remove" , " test.hjson" , " configuration.TEST_CONFIGURATION" , " bool2" )
113-
11448test [" shallow" ] = function ()
11549 local test_dir = " tests/tmp/ami_test_shallow"
11650 init_ami_test (test_dir , " tests/app/configs/ami_test_app@latest.hjson" , { cleanupTestDir = true })
0 commit comments