github.com/shashidharatd/test-infra@v0.0.0-20171006011030-71304e1ca560/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 ], 66 'dashboards': [ 67 { 68 'name': ['k8s'], 69 'dashboard_tab': [ 70 {'test_group_name': ['gce-serial'], 'name': ['serial']}, 71 ] 72 }, 73 { 74 'name': ['gce'], 75 'dashboard_tab': [ 76 {'test_group_name': ['gce-serial'], 'name': ['serial']}, 77 {'test_group_name': ['gce-soak'], 'name': ['soak']}, 78 {'test_group_name': ['gce-soak-1.3'], 'name': ['soak-1.3']}, 79 ] 80 }, 81 { 82 'name': ['1.3'], 83 'dashboard_tab': [ 84 {'test_group_name': ['gce-soak-1.3'], 'name': ['soak']}, 85 ] 86 }, 87 { 88 'name': ['gke'], 89 'dashboard_tab': [ 90 {'test_group_name': ['gke'], 'name': ['gke']} 91 ] 92 }, 93 { 94 'name': ['sig-storage'], 95 'dashboard_tab': [ 96 {'test_group_name': ['gke'], 'name': ['gke'], 97 'base_options': ['include-filter-by-regex=Storage']}, 98 {'test_group_name': ['gce-serial'], 'name': ['gce-serial'], 99 'base_options': ['include-filter-by-regex=Storage']} 100 ] 101 } 102 ] 103 } 104 def expect(path, out): 105 self.assertEqual(testgrid.path_to_query(path), out) 106 107 expect('/gce-serial/', 'k8s#serial') 108 expect('gce-soak', 'gce#soak') 109 expect('gce-soak-1.3', 'gce#soak-1.3') 110 expect('unusedgroup', '') 111 expect('notarealpath', '') 112 expect('gke', 'gke#gke') 113 114 115 class TestTestgridGCS(main_test.TestBase): 116 def test_write_config(self): 117 # pylint: disable=protected-access 118 self.init_stubs() 119 testgrid._testgrid_config = None 120 write_config() 121 path = 'kubernetes-jenkins/logs/somejob' 122 self.assertEqual( 123 testgrid.get_config(), 124 { 125 'test_groups': [{ 126 'name': ['tg'], 127 'query': [path] 128 }], 129 'dashboards': [{ 130 'dashboard_tab': [{'name': ['ajob'], 'test_group_name': ['tg']}], 131 'name': ['k8s'] 132 }], 133 }) 134 self.assertEqual(testgrid.path_to_query(path), 'k8s#ajob')