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

     1  # Copyright 2016 The Kubernetes Authors.
     2  #
     3  # Licensed under the Apache License, Version 2.0 (the "License");
     4  # you may not use this file except in compliance with the License.
     5  # You may obtain a copy of the License at
     6  #
     7  #     http://www.apache.org/licenses/LICENSE-2.0
     8  #
     9  # Unless required by applicable law or agreed to in writing, software
    10  # distributed under the License is distributed on an "AS IS" BASIS,
    11  # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  # See the License for the specific language governing permissions and
    13  # limitations under the License.
    14  
    15  import unittest
    16  
    17  import testgrid
    18  
    19  import main_test
    20  import pb_glance_test
    21  import gcs_async_test
    22  
    23  
    24  def write_config():
    25      tab = 'ajob'
    26      path = 'kubernetes-jenkins/logs/somejob'
    27      tab_len = 2 + len(tab) + 2 + 2
    28      data = pb_glance_test.tostr(
    29          [
    30              (1<<3)|2, 2 + 2 + 2 + len(path),  # testgroup
    31              (1<<3)|2, 2, 'tg',                # testgroup.name
    32              (2<<3)|2, len(path), path,        # testgroup.query
    33              (2<<3)|2, 2 + 3 + 2 + tab_len,        # dashboard
    34              (2<<3)|2, 3, 'k8s',               # dashboard.name
    35              (1<<3)|2, tab_len,                # dashboard.tab
    36              (1<<3)|2, len(tab), tab,          # dashboard.tab.name
    37              (2<<3)|2, len('tg'), 'tg',        # dashboard.tab.test_group_name
    38          ]
    39      )
    40      gcs_async_test.write('/k8s-testgrid/config', data)
    41  
    42  
    43  class TestTestgrid(unittest.TestCase):
    44      # pylint: disable=protected-access
    45  
    46      def test_path_to_group(self):
    47          testgrid._testgrid_config = {
    48              'test_groups': [
    49                  {'query': []},
    50                  {'query': ['foo']},
    51                  {'query': ['bar/e'], 'name': ['blah']},
    52              ]
    53          }
    54          self.assertEqual(testgrid.path_to_group_name('bar/e'), 'blah')
    55          self.assertEqual(testgrid.path_to_group_name('/blah'), None)
    56  
    57      def test_path_to_query(self):
    58          testgrid._testgrid_config = {
    59              'test_groups': [
    60                  {'query': ['gce-serial'], 'name': ['gce-serial']},
    61                  {'query': ['gce-soak'], 'name': ['gce-soak']},
    62                  {'query': ['gce-soak-1.3'], 'name': ['gce-soak-1.3']},
    63                  {'query': ['gke'], 'name': ['gke']},
    64                  {'query': ['unusedgroup'], 'name': ['unused']},
    65                  {'query': ['pr-logs/directory/pull-gce'], 'name': ['pull-gce']},
    66                  {'query': ['pr-logs/directory/pull-ti-verify'], 'name': ['pull-ti-verify']},
    67              ],
    68              'dashboards': [
    69                  {
    70                      'name': ['k8s'],
    71                      'dashboard_tab': [
    72                          {'test_group_name': ['gce-serial'], 'name': ['serial']},
    73                      ]
    74                  },
    75                  {
    76                      'name': ['gce'],
    77                      'dashboard_tab': [
    78                          {'test_group_name': ['gce-serial'], 'name': ['serial']},
    79                          {'test_group_name': ['gce-soak'], 'name': ['soak']},
    80                          {'test_group_name': ['gce-soak-1.3'], 'name': ['soak-1.3']},
    81                      ]
    82                  },
    83                  {
    84                      'name': ['1.3'],
    85                      'dashboard_tab': [
    86                          {'test_group_name': ['gce-soak-1.3'], 'name': ['soak']},
    87                      ]
    88                  },
    89                  {
    90                      'name': ['gke'],
    91                      'dashboard_tab': [
    92                         {'test_group_name': ['gke'], 'name': ['gke']}
    93                      ]
    94                  },
    95                  {
    96                      'name': ['sig-storage'],
    97                      'dashboard_tab': [
    98                         {'test_group_name': ['gke'], 'name': ['gke'],
    99                           'base_options': ['include-filter-by-regex=Storage']},
   100                         {'test_group_name': ['gce-serial'], 'name': ['gce-serial'],
   101                           'base_options': ['include-filter-by-regex=Storage']}
   102                      ]
   103                  },
   104                  {
   105                      'name': ['pull'],
   106                      'dashboard_tab': [
   107                         {'test_group_name': ['pull-gce'], 'name': ['gce'],
   108                          'base_options': ['width=10']},
   109                      ]
   110                  },
   111                  {
   112                      'name': ['pull-ti'],
   113                      'dashboard_tab': [
   114                         {'test_group_name': ['pull-ti-verify'], 'name': ['verify']},
   115                      ]
   116                  },
   117              ]
   118          }
   119          def expect(path, out):
   120              self.assertEqual(testgrid.path_to_query(path), out)
   121  
   122          expect('/gce-serial/', 'k8s#serial')
   123          expect('gce-soak', 'gce#soak')
   124          expect('gce-soak-1.3', 'gce#soak-1.3')
   125          expect('unusedgroup', '')
   126          expect('notarealpath', '')
   127          expect('gke', 'gke#gke')
   128          expect('pr-logs/pull/123/pull-gce/', 'pull#gce')
   129          expect('pr-logs/pull/ti/123/pull-ti-verify/', 'pull-ti#verify')
   130  
   131  
   132  class TestTestgridGCS(main_test.TestBase):
   133      def test_write_config(self):
   134          # pylint: disable=protected-access
   135          self.init_stubs()
   136          testgrid._testgrid_config = None
   137          write_config()
   138          path = 'kubernetes-jenkins/logs/somejob'
   139          self.assertEqual(
   140              testgrid.get_config(),
   141              {
   142                  'test_groups': [{
   143                      'name': ['tg'],
   144                      'query': [path]
   145                  }],
   146                  'dashboards': [{
   147                      'dashboard_tab': [{'name': ['ajob'], 'test_group_name': ['tg']}],
   148                      'name': ['k8s']
   149                  }],
   150              })
   151          self.assertEqual(testgrid.path_to_query(path), 'k8s#ajob')