1# Copyright 2023 The Bazel Authors. All rights reserved. 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"" 16 17load("@io_bazel_rules_go//go:def.bzl", "go_test") 18 19def gazelle_test(*, name, test_dirs, **kwargs): 20 """A simple macro to better cache gazelle integration tests 21 22 Args: 23 name (str): The name of the test suite target to be created and 24 the prefix to all of the individual test targets. 25 test_dirs (list[str]): The list of dirs in the 'testdata' 26 directory that we should create separate 'go_test' cases for. 27 Each of them will be prefixed with '{name}'. 28 **kwargs: extra arguments passed to 'go_test'. 29 """ 30 tests = [] 31 32 data = kwargs.pop("data", []) 33 34 for dir in test_dirs: 35 _, _, basename = dir.rpartition("/") 36 37 test = "{}_{}".format(name, basename) 38 tests.append(test) 39 40 go_test( 41 name = test, 42 data = native.glob(["{}/**".format(dir)]) + data, 43 **kwargs 44 ) 45 46 native.test_suite( 47 name = name, 48 tests = tests, 49 ) 50