aboutsummaryrefslogtreecommitdiff
path: root/spec/util/test_env.lua
diff options
context:
space:
mode:
Diffstat (limited to 'spec/util/test_env.lua')
-rw-r--r--spec/util/test_env.lua117
1 files changed, 65 insertions, 52 deletions
diff --git a/spec/util/test_env.lua b/spec/util/test_env.lua
index f311a370..15aa554d 100644
--- a/spec/util/test_env.lua
+++ b/spec/util/test_env.lua
@@ -809,52 +809,6 @@ local function get_luarocks_platform(variables)
809 return execute_output(cmd, false, variables) 809 return execute_output(cmd, false, variables)
810end 810end
811 811
812--- Function for initial setup of environment, variables, md5sums for spec files
813function test_env.setup_specs(extra_rocks)
814 local testrun_dir = test_env.testing_paths.testrun_dir
815 local variables = test_env.env_variables
816
817 -- if global variable about successful creation of testing environment doesn't exist, build environment
818 if not test_env.setup_done then
819 if test_env.CI then
820 if not exists(os.getenv("HOME"), ".ssh/id_rsa.pub") then
821 execute_bool("ssh-keygen -t rsa -P \"\" -f ~/.ssh/id_rsa")
822 execute_bool("cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys")
823 execute_bool("chmod og-wx ~/.ssh/authorized_keys")
824 execute_bool("ssh-keyscan localhost >> ~/.ssh/known_hosts")
825 end
826 end
827
828 test_env.main()
829
830 -- preload before meddling with package.path
831 require("spec.util.git_repo")
832 require("spec.util.quick")
833
834 package.path = variables.LUA_PATH
835 package.cpath = variables.LUA_CPATH
836
837 test_env.platform = get_luarocks_platform(test_env.env_variables)
838 test_env.wrapper_extension = test_env.TEST_TARGET_OS == "windows" and ".bat" or ""
839 test_env.md5sums = create_md5sums(test_env.testing_paths)
840 test_env.setup_done = true
841 title("RUNNING TESTS")
842 end
843
844 if extra_rocks then
845 local make_manifest = download_rocks(extra_rocks, test_env.testing_paths.testing_server)
846 if make_manifest then
847 test_env.run.luarocks_admin_nocov("make_manifest " .. test_env.testing_paths.testing_server)
848 end
849 end
850
851 if test_env.RESET_ENV then
852 reset_environment(test_env.testing_paths, test_env.md5sums, variables)
853 end
854
855 lfs.chdir(testrun_dir)
856end
857
858--- Test if required rock is installed and if not, install it. 812--- Test if required rock is installed and if not, install it.
859-- Return `true` if the rock is already installed or has been installed successfully, 813-- Return `true` if the rock is already installed or has been installed successfully,
860-- `false` if installation failed. 814-- `false` if installation failed.
@@ -1024,10 +978,14 @@ local function setup_luarocks()
1024end 978end
1025 979
1026local function mock_api_call(path) 980local function mock_api_call(path)
1027 test_env.execute(C(tool("wget"), "--quiet --timeout=5 --tries=1 localhost:8080" .. path)) 981 return test_env.execute(C(tool("wget"), "--timeout=0.1 --quiet --tries=10 http://localhost:8080" .. path))
1028end 982end
1029 983
1030function test_env.mock_server_init() 984function test_env.mock_server_init()
985 if not test_env.mock_prepared then
986 error("need to setup_specs with with_mock set to true")
987 end
988
1031 local testing_paths = test_env.testing_paths 989 local testing_paths = test_env.testing_paths
1032 assert(test_env.need_rock("restserver-xavante")) 990 assert(test_env.need_rock("restserver-xavante"))
1033 991
@@ -1043,14 +1001,13 @@ function test_env.mock_server_init()
1043 1001
1044 os.execute(test_env.execute_helper(bg_cmd, true, test_env.env_variables)) 1002 os.execute(test_env.execute_helper(bg_cmd, true, test_env.env_variables))
1045 1003
1046 for _ = 1, 10 do 1004 for _ = 1, 100 do
1047 if mock_api_call("/api/tool_version") then 1005 if mock_api_call("/api/tool_version") then
1048 break 1006 break
1049 end 1007 end
1050
1051 os.execute(test_env.TEST_TARGET_OS == "windows" 1008 os.execute(test_env.TEST_TARGET_OS == "windows"
1052 and "timeout 1 > NUL" 1009 and "ping 192.0.2.0 -n 1 -w 250 > NUL"
1053 or "sleep 1") 1010 or "sleep 0.1")
1054 end 1011 end
1055 1012
1056end 1013end
@@ -1070,6 +1027,10 @@ local function find_binary_rock(src_rock, dirname)
1070end 1027end
1071 1028
1072local function prepare_mock_server_binary_rocks() 1029local function prepare_mock_server_binary_rocks()
1030 if test_env.mock_prepared then
1031 return
1032 end
1033
1073 local testing_paths = test_env.testing_paths 1034 local testing_paths = test_env.testing_paths
1074 1035
1075 local rocks = { 1036 local rocks = {
@@ -1106,6 +1067,8 @@ local function prepare_mock_server_binary_rocks()
1106 if make_manifest then 1067 if make_manifest then
1107 test_env.run.luarocks_admin_nocov(C("make_manifest", Q(testing_paths.testing_server))) 1068 test_env.run.luarocks_admin_nocov(C("make_manifest", Q(testing_paths.testing_server)))
1108 end 1069 end
1070
1071 test_env.mock_prepared = true
1109end 1072end
1110 1073
1111--- 1074---
@@ -1169,8 +1132,58 @@ function test_env.main()
1169 download_rocks(urls, testing_paths.testing_server) 1132 download_rocks(urls, testing_paths.testing_server)
1170 1133
1171 build_environment(rocks, env_vars) 1134 build_environment(rocks, env_vars)
1135end
1136
1137--- Function for initial setup of environment, variables, md5sums for spec files
1138function test_env.setup_specs(extra_rocks, use_mock)
1139 test_env.unload_luarocks()
1140
1141 local testrun_dir = test_env.testing_paths.testrun_dir
1142 local variables = test_env.env_variables
1143
1144 -- if global variable about successful creation of testing environment doesn't exist, build environment
1145 if not test_env.setup_done then
1146 if test_env.CI then
1147 if not exists(os.getenv("HOME"), ".ssh/id_rsa.pub") then
1148 execute_bool("ssh-keygen -t rsa -P \"\" -f ~/.ssh/id_rsa")
1149 execute_bool("cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys")
1150 execute_bool("chmod og-wx ~/.ssh/authorized_keys")
1151 execute_bool("ssh-keyscan localhost >> ~/.ssh/known_hosts")
1152 end
1153 end
1154
1155 test_env.main()
1156
1157 -- preload before meddling with package.path
1158 require("spec.util.git_repo")
1159 require("spec.util.quick")
1172 1160
1173 prepare_mock_server_binary_rocks() 1161 package.path = variables.LUA_PATH
1162 package.cpath = variables.LUA_CPATH
1163
1164 test_env.platform = get_luarocks_platform(test_env.env_variables)
1165 test_env.wrapper_extension = test_env.TEST_TARGET_OS == "windows" and ".bat" or ""
1166 test_env.md5sums = create_md5sums(test_env.testing_paths)
1167 test_env.setup_done = true
1168 title("RUNNING TESTS")
1169 end
1170
1171 if use_mock == "mock" then
1172 prepare_mock_server_binary_rocks()
1173 end
1174
1175 if extra_rocks then
1176 local make_manifest = download_rocks(extra_rocks, test_env.testing_paths.testing_server)
1177 if make_manifest then
1178 test_env.run.luarocks_admin_nocov("make_manifest " .. test_env.testing_paths.testing_server)
1179 end
1180 end
1181
1182 if test_env.RESET_ENV then
1183 reset_environment(test_env.testing_paths, test_env.md5sums, variables)
1184 end
1185
1186 lfs.chdir(testrun_dir)
1174end 1187end
1175 1188
1176test_env.set_lua_version() 1189test_env.set_lua_version()