def test_add_envs_dont_call_set_when_variables_dont_change(self): plugin = ApprcWatcher("", "", 1) envs = copy.deepcopy(NOPATH_OUTPUT) envs["options"]["env"].update(os.environ) plugin.call, kw = create_fake_call(None, envs) plugin.add_envs(name="name", envs=NOPATH_OUTPUT["options"]["env"]) self.assertEqual([], kw)
def test_reload_env_skips_plugins(self): sr = { "statuses": { "name": "name", "plugin:tsuru-circus-ApprcWatcher": "ok" } } fake_call, kw = create_fake_call(sr) plugin = ApprcWatcher("", "", 1) plugin.call = fake_call plugin.apprc = os.path.join(os.path.dirname(__file__), "testdata/apprc") plugin.reload_env() env = { "VAR1": "value-1", "port": "8888", "VAR2": "value2", "PORT": "8888" } env.update(os.environ) expected = [ { "name": "name", "options": { "env": env } }, ] self.assertEqual(expected, kw)
def test_reload_env_add_envs(self): sr = {"statuses": {"name": "name", "cmd": "cmd"}} fake_call, kw = create_fake_call(sr) plugin = ApprcWatcher("", "", 1) plugin.call = fake_call plugin.apprc = os.path.join(os.path.dirname(__file__), "testdata/apprc") plugin.reload_env() env = { "VAR1": "value-1", "port": "8888", "VAR2": "value2", "PORT": "8888" } env.update(os.environ) expected = [ { "name": "cmd", "options": { "env": env } }, { "name": "name", "options": { "env": env } }, ] self.assertEqual(expected, sorted(kw, key=lambda x: x["name"]))
def test_add_envs(self): plugin = ApprcWatcher("", "", 1) plugin.call, kw = create_fake_call(None) plugin.add_envs(name="name", envs={"foo": "bar"}) env = copy.deepcopy(os.environ) env["foo"] = "bar" expected = [{"name": "name", "options": {"env": env}}] self.assertEqual(expected, kw)
def test_add_env_ignores_PYTHONPATH_from_os_environ(self): os.environ["PYTHONPATH"] = "/home/user/python" self.addCleanup(remove_env, "PYTHONPATH") plugin = ApprcWatcher("", "", 1) plugin.call, kw = create_fake_call(None) plugin.add_envs(name="name", envs={"foo": "bar"}) env = copy.deepcopy(os.environ) env["foo"] = "bar" del env["PYTHONPATH"] expected = [{"name": "name", "options": {"env": env}}] self.assertEqual(expected, kw)
def test_add_env_doesnt_ignore_PYTHONPATH_from_apprc(self): plugin = ApprcWatcher("", "", 1) plugin.call, kw = create_fake_call(None) plugin.add_envs(name="name", envs={ "foo": "bar", "PYTHONPATH": "/usr/lib/python" }) env = copy.deepcopy(os.environ) env["foo"] = "bar" env["PYTHONPATH"] = "/usr/lib/python" expected = [{"name": "name", "options": {"env": env}}] self.assertEqual(expected, kw)
def test_add_envs_may_override_os_environ(self): os.environ["SOMETHING_UNKNOWN"] = "123" self.addCleanup(remove_env, "SOMETHING_UNKNOWN") plugin = ApprcWatcher("", "", 1) plugin.call, kw = create_fake_call(None) plugin.add_envs(name="name", envs={ "foo": "bar", "SOMETHING_UNKNOWN": "456" }) env = copy.deepcopy(os.environ) env["SOMETHING_UNKNOWN"] = "456" env["foo"] = "bar" expected = [{"name": "name", "options": {"env": env}}] self.assertEqual(expected, kw)