def test_template_render_for_container_level_variables(self): roger_push = RogerPush() app_data = self.config['apps']['grafana_test_app'] container = "grafana" # Passing environment that doesn't exist output = roger_push.renderTemplate(self.template, "non_existing_env", "test_image", app_data, self.config, container, "grafana", self.additional_vars) result = json.loads(output) assert result['env']['ENV_VAR1'] == '3' assert result['env']['ENV_VAR2'] == '3' # Existing environment output = roger_push.renderTemplate(self.template, "test", "test_image", app_data, self.config, container, "grafana", self.additional_vars) result = json.loads(output) assert result['env']['ENV_VAR1'] == '4' assert result['env']['ENV_VAR2'] == '8' container = app_data['containers'][1]['grafana1'] output = roger_push.renderTemplate(self.template, "non_existing_env", "test_image", app_data, self.config, container, "grafana1", self.additional_vars) result = json.loads(output) assert result['env']['ENV_VAR1'] == '30' assert result['env']['ENV_VAR2'] == '54' output = roger_push.renderTemplate(self.template, "test", "test_image", app_data, self.config, container, "grafana1", self.additional_vars) result = json.loads(output) assert result['env']['ENV_VAR1'] == '64' assert result['env']['ENV_VAR2'] == '128'
def test_template_render_for_container_level_variables(self): roger_push = RogerPush() app_data = self.config['apps']['grafana_test_app'] container = "grafana" # Passing environment that doesn't exist output = roger_push.renderTemplate(self.template, "non_existing_env", "test_image", app_data, self.config, container, "grafana", self.additional_vars) result = json.loads(output) assert result['env']['ENV_VAR1'] == '3' assert result['env']['ENV_VAR2'] == '3' # Existing environment output = roger_push.renderTemplate( self.template, "test", "test_image", app_data, self.config, container, "grafana", self.additional_vars) result = json.loads(output) assert result['env']['ENV_VAR1'] == '4' assert result['env']['ENV_VAR2'] == '8' container = app_data['containers'][1]['grafana1'] output = roger_push.renderTemplate(self.template, "non_existing_env", "test_image", app_data, self.config, container, "grafana1", self.additional_vars) result = json.loads(output) assert result['env']['ENV_VAR1'] == '30' assert result['env']['ENV_VAR2'] == '54' output = roger_push.renderTemplate( self.template, "test", "test_image", app_data, self.config, container, "grafana1", self.additional_vars) result = json.loads(output) assert result['env']['ENV_VAR1'] == '64' assert result['env']['ENV_VAR2'] == '128'
def test_secret_vars_replacement_with_secrets_file(self): args = self.args args.env = "test" args.secrets_file = "test_app-container1.json" args.app_name = 'test_app' args.image_name = 'test_image' secrets_dir = self.base_dir + "/tests/secrets" roger_push = RogerPush() app_data = self.config['apps'][args.app_name] container = "container1" additional_vars = self.additional_vars extra_vars = {} extra_vars['env_value1'] = "100" extra_vars['env_value2'] = "200" additional_vars.update(extra_vars) secret_vars = roger_push.loadSecrets(secrets_dir, args.secrets_file, args, args.env) print(secret_vars) additional_vars.update(secret_vars) output = roger_push.renderTemplate(self.template, args.env, args.image_name, app_data, self.config, container, "container1", additional_vars) result = json.loads(output) assert result['env']['ENV_VAR1'] == 'test_value1' assert result['env']['ENV_VAR2'] == 'test_value2'
def test_template_render_for_app_level_variables(self): roger_push = RogerPush() app_data = self.config['apps']['test_app1'] container = "container_name1" # Passing environment that doesn't exist output = roger_push.renderTemplate(self.template, "non_existing_env", "test_image", app_data, self.config, container, "container_name1", self.additional_vars) result = json.loads(output) assert result['env']['ENV_VAR1'] == '12' assert result['env']['ENV_VAR2'] == '16' # Existing environment output = roger_push.renderTemplate( self.template, "test", "test_image", app_data, self.config, container, "container_name1", self.additional_vars) result = json.loads(output) assert result['env']['ENV_VAR1'] == '20' assert result['env']['ENV_VAR2'] == '24'
def test_secret_vars_replacement_with_secrets_file(self): args = self.args args.env = "test" args.secrets_file = "test_app-container1.json" args.app_name = 'test_app' args.image_name = 'test_image' args.verbose = False secrets_dir = self.base_dir + "/tests/secrets" roger_push = RogerPush() app_data = self.config['apps'][args.app_name] container = "container1" additional_vars = self.additional_vars extra_vars = {} extra_vars['env_value1'] = "100" extra_vars['env_value2'] = "200" additional_vars.update(extra_vars) secret_vars = roger_push.loadSecrets( secrets_dir, args.secrets_file, args, args.env) print(secret_vars) additional_vars.update(secret_vars) output = roger_push.renderTemplate( self.template, args.env, args.image_name, app_data, self.config, container, "container1", additional_vars) result = json.loads(output) assert result['env']['ENV_VAR1'] == 'test_value1' assert result['env']['ENV_VAR2'] == 'test_value2'
def test_template_render_for_config_level_variables(self): roger_push = RogerPush() app_data = self.config['apps']['test_app'] container = "container_name1" output = roger_push.renderTemplate( self.template, "test", "test_image", app_data, self.config, container, "container_name1", self.additional_vars) result = json.loads(output) assert result['env']['ENV_VAR1'] == '4' assert result['env']['ENV_VAR2'] == '8'
def test_template_render_for_extra_variables(self): roger_push = RogerPush() app_data = self.config['apps']['grafana_test_app'] container = app_data['containers'][1]['grafana1'] additional_vars = self.additional_vars additional_vars['env_value1'] = "100" additional_vars['env_value2'] = "200" output = roger_push.renderTemplate( self.template, "test", "test_image", app_data, self.config, container, "grafana1", additional_vars) result = json.loads(output) assert result['env']['ENV_VAR1'] == '100' assert result['env']['ENV_VAR2'] == '200'