示例#1
0
 def testEnvLiteralSetFailsWhenOtherTypeExists(self):
   self.template.env_vars.secrets.update({
       'k1': self._MakeSecretEnvVarSource('s1', 'key'),
   })
   env_change = config_changes.EnvVarLiteralChanges(
       env_vars_to_update={'k1': 'x1'},
       clear_others=True)
   with self.assertRaises(exceptions.ConfigurationError):
     self.resource = env_change.Adjust(self.resource)
示例#2
0
 def testEnvLiteralUpdateEmptyString(self):
   # Because the `value` field is omitempty, when an empty string is passed
   # as the value the field is left unset. Assigning the value to None here
   # replicates that unset behavior.
   self.template.env_vars.literals.update({'k1': None})
   env_change = config_changes.EnvVarLiteralChanges(
       env_vars_to_update={'k1': 'v1'})
   self.resource = env_change.Adjust(self.resource)
   self.assertDictEqual({'k1': 'v1'}, dict(self.template.env_vars.literals))
示例#3
0
 def testEnvLiteralUpdate(self):
   self.template.env_vars.literals.update({'k1': 'v1', 'k2': 'v2'})
   env_change = config_changes.EnvVarLiteralChanges(
       env_vars_to_update={'k1': 'x1', 'k3': 'v3'})
   self.resource = env_change.Adjust(self.resource)
   self.assertDictEqual({
       'k1': 'x1',
       'k2': 'v2',
       'k3': 'v3',
   }, dict(self.template.env_vars.literals))
示例#4
0
def _GetEnvChanges(args):
  """Return config_changes.EnvVarLiteralChanges for given args."""
  kwargs = {}

  update = args.update_env_vars or args.set_env_vars
  if update:
    kwargs['env_vars_to_update'] = update

  remove = args.remove_env_vars
  if remove:
    kwargs['env_vars_to_remove'] = remove

  if args.set_env_vars or args.clear_env_vars:
    kwargs['clear_others'] = True

  return config_changes.EnvVarLiteralChanges(**kwargs)
示例#5
0
 def testEnvLiteralRemoveWithSpace(self):
   self.template.env_vars.literals.update({'k1': 'v1', 'k2': 'v2'})
   env_change = config_changes.EnvVarLiteralChanges(
       env_vars_to_remove=['  k1'])
   self.resource = env_change.Adjust(self.resource)
   self.assertDictEqual({'k2': 'v2'}, dict(self.template.env_vars.literals))