k8s.io/test-infra@v0.0.0-20240520184403-27c6b4c223d8/releng/generate_tests_test.py (about)

     1  #!/usr/bin/env python3
     2  
     3  # Copyright 2019 The Kubernetes Authors.
     4  #
     5  # Licensed under the Apache License, Version 2.0 (the "License");
     6  # you may not use this file except in compliance with the License.
     7  # You may obtain a copy of the License at
     8  #
     9  #     http://www.apache.org/licenses/LICENSE-2.0
    10  #
    11  # Unless required by applicable law or agreed to in writing, software
    12  # distributed under the License is distributed on an "AS IS" BASIS,
    13  # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    14  # See the License for the specific language governing permissions and
    15  # limitations under the License.
    16  
    17  import unittest
    18  import tempfile
    19  import shutil
    20  from generate_tests import E2ETest
    21  
    22  class TestGenerateTests(unittest.TestCase):
    23  
    24      def setUp(self):
    25          self.temp_directory = tempfile.mkdtemp()
    26          self.job_name = "ci-kubernetes-e2e-cloud_a-image_b-k8sfoo-focus_c"
    27          self.job = {
    28              "interval": "1h"
    29          }
    30          self.config = {
    31              "jobs": {"ci-kubernetes-e2e-cloud_a-image_b-k8sfoo-focus_c": self.job},
    32              "common": {"args": []},
    33              "cloudProviders": {"cloud_a": {"args": []}},
    34              "images": {"image_b": {}},
    35              "k8sVersions": {"foo": {"version": "2.4"}},
    36              "testSuites": {"focus_c": {"args": ["--timeout=10"]}},
    37          }
    38  
    39      def tearDown(self):
    40          shutil.rmtree(self.temp_directory)
    41  
    42      def test_e2etests_testgrid_annotations_default(self):
    43          generator = E2ETest(self.temp_directory, self.job_name, self.job, self.config)
    44          _, prow_config, _ = generator.generate()
    45          dashboards = prow_config["annotations"]["testgrid-dashboards"]
    46          self.assertFalse("sig-release-2.4-blocking" in dashboards)
    47          self.assertTrue("sig-release-generated" in dashboards)
    48  
    49      def test_e2etests_testgrid_annotations_blocking_job(self):
    50          self.job = {
    51              "releaseBlocking": True,
    52              "interval": "1h"
    53          }
    54  
    55          generator = E2ETest(self.temp_directory, self.job_name, self.job, self.config)
    56          _, prow_config, _ = generator.generate()
    57          dashboards = prow_config["annotations"]["testgrid-dashboards"]
    58          self.assertTrue("sig-release-2.4-blocking" in dashboards)
    59          self.assertFalse("sig-release-generated" in dashboards)
    60  
    61  
    62  if __name__ == '__main__':
    63      unittest.main()