summaryrefslogtreecommitdiff
path: root/testing
diff options
context:
space:
mode:
authorDaniel Silverstone <daniel.silverstone@codethink.co.uk>2017-05-13 15:14:34 +0100
committerDaniel Silverstone <dsilvers@digital-scurf.org>2017-06-17 15:03:00 +0100
commitea637c6dbc4d50239e0d5b7b57b08a724d3bb5e3 (patch)
tree73d83398ee876782b7bc2f0c9404729af98e75fe /testing
parent7c992daade9445584d2f233c722500d426546361 (diff)
downloadgitano-ea637c6dbc4d50239e0d5b7b57b08a724d3bb5e3.tar.gz
Add support for ENV vars in gitano-test-tool
This adds support for gitano-test-tool to set environment variables. We also add some yarn implementations for doing this.
Diffstat (limited to 'testing')
-rw-r--r--testing/gitano-test-tool.in34
-rw-r--r--testing/library.yarn6
2 files changed, 39 insertions, 1 deletions
diff --git a/testing/gitano-test-tool.in b/testing/gitano-test-tool.in
index f467918..1fd39b0 100644
--- a/testing/gitano-test-tool.in
+++ b/testing/gitano-test-tool.in
@@ -70,10 +70,28 @@ local function unix_assert(ret, errno)
end
end
+local function load_env(into)
+ local f, msg = loadfile(basedir .. ".gtt-env")
+ if f then
+ setfenv(f, into)
+ f()
+ end
+end
+
+local function save_env(env)
+ local f = io.open(basedir .. ".gtt-env", "w")
+ for k, v in pairs(env) do
+ f:write(("%s = %q\n"):format(k, v))
+ end
+ f:close()
+end
+
local function run_program(t)
- if t.env and os.getenv("GITANO_DUMP_VARIABLE_FILE") then
+ t.env = (t.env or {})
+ if os.getenv("GITANO_DUMP_VARIABLE_FILE") then
t.env["GITANO_DUMP_VARIABLE_FILE"] = os.getenv("GITANO_DUMP_VARIABLE_FILE")
end
+ load_env(t.env)
local f = io.open(basedir .. "last-program", "w")
local function print (...)
f:write(...)
@@ -180,6 +198,20 @@ function cmd_setgitconfig(username, key, value)
}
end
+function cmd_setenv(key, value)
+ local t = {}
+ load_env(t)
+ t[key] = value
+ save_env(t)
+end
+
+function cmd_unsetenv(key)
+ local t = {}
+ load_env(t)
+ t[key] = nil
+ save_env(t)
+end
+
function cmd_createunixuser(username)
assert(sio.mkdir(user_home(username), "0755"))
assert(sio.mkdir(ssh_base(username), "0755"))
diff --git a/testing/library.yarn b/testing/library.yarn
index 6facf2a..a370bfe 100644
--- a/testing/library.yarn
+++ b/testing/library.yarn
@@ -283,6 +283,12 @@ Generic utility methods
IMPLEMENTS ASSUMING gitano is being accessed over ([^ ]+)
test "$GTT_PROTO" = "$MATCH_1"
+ IMPLEMENTS GIVEN ([^ ]+) is in the environment set to (.+)
+ $GTT setenv "$MATCH_1" "$MATCH_2"
+
+ IMPLEMENTS GIVEN ([^ ]+) is not in the environment
+ $GTT unsetenv "$MATCH_1"
+
GPG Keyring related helpers
---------------------------