1+ #! /bin/bash
2+ #
3+ # SPDX-FileCopyrightText: Copyright (c) 2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
4+ # SPDX-License-Identifier: Apache-2.0
5+ #
6+ # Licensed under the Apache License, Version 2.0 (the "License");
7+ # you may not use this file except in compliance with the License.
8+ # You may obtain a copy of the License at
9+ #
10+ # http://www.apache.org/licenses/LICENSE-2.0
11+ #
12+ # Unless required by applicable law or agreed to in writing, software
13+ # distributed under the License is distributed on an "AS IS" BASIS,
14+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+ # See the License for the specific language governing permissions and
16+ # limitations under the License.
17+
18+ # Reference:
19+ # https://bats-core.readthedocs.io/en/latest/writing-tests.html#setup-and-teardown-pre-and-post-test-hooks
20+
21+ # Validate that some prerequisites are met, and inspect environment for
22+ # characteristics, such as DRA API group version. A failing setup_suit()
23+ # function aborts the suite (fail fast).
24+ setup_suite () {
25+ # Probe: kubectl configured against a k8s cluster.
26+ kubectl cluster-info | grep " control plane is running at"
27+
28+ # Show, for debugging.
29+ kubectl api-resources --api-group=resource.k8s.io
30+
31+ # Require DRA API group to be enabled (for now, maybe we want to add a test
32+ # later that shows how Helm chart installation fails when DRA is not
33+ # enabled, and then this suite-setup check could get in the way). The
34+ # command below is expected to emit deviceclasses, resourceclaims,
35+ # resourceclaimtemplates, resourceslices -- probe just one.
36+ kubectl api-resources --api-group=resource.k8s.io | grep resourceslices
37+
38+ TEST_K8S_RESOURCE_API_VERSION=$( \
39+ kubectl api-resources --api-group=resource.k8s.io -o json | \
40+ jq -r ' .resources | map(select(.version)) | .[0].version'
41+ )
42+
43+ # Examples: v1, or v1beta1
44+ export TEST_K8S_RESOURCE_API_VERSION
45+ }
0 commit comments