def test_template(self):
    extra_configs = [{
        'name': 'Public service and ingress',
        'env_vars': ['PUBLIC_SERVICE_AND_INGRESS_ENABLED=true']
    }]
    cloudbuild_template = """
    steps:
    - id: Build {{ solution }}
      name: gcr.io/cloud-builders/docker
      dir: k8s

    {%- for extra_config in extra_configs %}

    - id: Verify {{ solution }} ({{ extra_config['name'] }})
      name: gcr.io/cloud-builders/docker
      dir: k8s
      env:
      {%- for env_var in extra_config['env_vars'] %}
      - '{{ env_var }}'
      {%- endfor %}

    {%- endfor %}
    """.strip()

    cloudbuild = cloudbuild_k8s_generator.CloudBuildConfig(solution='wordpress')
    self.assertIsNotNone(cloudbuild.generate())

    cloudbuild = cloudbuild_k8s_generator.CloudBuildConfig(solution='wordpress')
    cloudbuild.extra_configs = []
    self.assertIsNotNone(cloudbuild.generate())

    cloudbuild = cloudbuild_k8s_generator.CloudBuildConfig(solution='wordpress')
    cloudbuild.template = cloudbuild_template
    self.assertEqual(
        cloudbuild.generate(), """
    steps:
    - id: Build wordpress
      name: gcr.io/cloud-builders/docker
      dir: k8s
    """.strip())

    cloudbuild = cloudbuild_k8s_generator.CloudBuildConfig(solution='wordpress')
    cloudbuild.extra_configs = extra_configs
    cloudbuild.template = cloudbuild_template
    self.assertEqual(
        cloudbuild.generate(), """
    steps:
    - id: Build wordpress
      name: gcr.io/cloud-builders/docker
      dir: k8s

    - id: Verify wordpress (Public service and ingress)
      name: gcr.io/cloud-builders/docker
      dir: k8s
      env:
      - 'PUBLIC_SERVICE_AND_INGRESS_ENABLED=true'
    """.strip())
Пример #2
0
 def test_remove(self):
     with tempfile.NamedTemporaryFile(delete=False) as f:
         cloudbuild = cloudbuild_k8s_generator.CloudBuildConfig(
             solution='wordpress')
         cloudbuild.path = f.name
         cloudbuild.remove()
         self.assertFalse(cloudbuild.exists)
Пример #3
0
 def test_save(self):
     cloudbuild_config = """
 steps:
 - id: Build unknown
   name: gcr.io/cloud-builders/docker
   dir: k8s
 """
     with tempfile.NamedTemporaryFile(delete=True) as f:
         cloudbuild = cloudbuild_k8s_generator.CloudBuildConfig(
             solution='wordpress')
         cloudbuild.template = cloudbuild_config
         cloudbuild.path = f.name
         cloudbuild.save()
         self.assertEqual(f.read(), cloudbuild_config)
  def test_generate(self):
    extra_configs = [{
        'name':
            'Public service and ingress',
        'env_vars': [
            'PUBLIC_SERVICE_AND_INGRESS_ENABLED=true',
            'METRICS_EXPORTER_ENABLED=true'
        ]
    }]

    cloudbuild = cloudbuild_k8s_generator.CloudBuildConfig(solution='wordpress')
    self.assertEqual(cloudbuild.generate(), CLOUDBUILD_OUTPUT)

    cloudbuild.extra_configs = extra_configs
    self.assertEqual(cloudbuild.generate(), CLOUDBUILD_OUTPUT_WITH_EXTRA_CONFIG)
  def test_verify(self):
    cloudbuild_config = """
    steps:
    - id: Build unknown
      name: gcr.io/cloud-builders/docker
      dir: k8s
    """
    cloudbuild_template = """
    steps:
    - id: Build {{ solution }}
      name: gcr.io/cloud-builders/docker
      dir: k8s
    """
    with tempfile.NamedTemporaryFile(delete=True) as f:
      f.write(cloudbuild_config)
      f.flush()

      cloudbuild = cloudbuild_k8s_generator.CloudBuildConfig(solution='unknown')
      cloudbuild.path = f.name
      self.assertFalse(cloudbuild.verify())

      cloudbuild.template = cloudbuild_template
      self.assertTrue(cloudbuild.verify())
Пример #6
0
 def test_exists(self):
     with tempfile.NamedTemporaryFile(delete=True) as f:
         cloudbuild = cloudbuild_k8s_generator.CloudBuildConfig(
             solution='unknown')
         cloudbuild.path = f.name
         self.assertTrue(cloudbuild.exists)
Пример #7
0
 def test_path(self):
     cloudbuild = cloudbuild_k8s_generator.CloudBuildConfig(
         solution='wordpress')
     cloudbuild.path = '/tmp/wordpress.yaml'
     self.assertEqual(cloudbuild.path, '/tmp/wordpress.yaml')