|
| 1 | +/* |
| 2 | +Copyright 2025 The Kubernetes Authors. |
| 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 | +http://www.apache.org/licenses/LICENSE-2.0 |
| 7 | +Unless required by applicable law or agreed to in writing, software |
| 8 | +distributed under the License is distributed on an "AS IS" BASIS, |
| 9 | +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 10 | +See the License for the specific language governing permissions and |
| 11 | +limitations under the License. |
| 12 | +*/ |
| 13 | +package io.kubernetes.client.openapi; |
| 14 | + |
| 15 | +import static org.assertj.core.api.Assertions.assertThat; |
| 16 | + |
| 17 | +import java.util.Collections; |
| 18 | +import okhttp3.Request; |
| 19 | +import org.junit.jupiter.api.Test; |
| 20 | + |
| 21 | +class ApiClientTest { |
| 22 | + |
| 23 | + @Test |
| 24 | + void testUserAgentMatchesConfigurationVersion() throws ApiException { |
| 25 | + ApiClient apiClient = new ApiClient(); |
| 26 | + |
| 27 | + // Build a simple request to verify User-Agent header |
| 28 | + Request request = |
| 29 | + apiClient.buildRequest( |
| 30 | + "http://localhost", |
| 31 | + "/api/v1/test", |
| 32 | + "GET", |
| 33 | + Collections.emptyList(), |
| 34 | + Collections.emptyList(), |
| 35 | + null, |
| 36 | + Collections.emptyMap(), |
| 37 | + Collections.emptyMap(), |
| 38 | + Collections.emptyMap(), |
| 39 | + new String[] {}, |
| 40 | + null); |
| 41 | + |
| 42 | + // Verify the User-Agent header matches the version from Configuration |
| 43 | + String expectedUserAgent = "Kubernetes Java Client/" + Configuration.VERSION; |
| 44 | + String actualUserAgent = request.header("User-Agent"); |
| 45 | + |
| 46 | + assertThat(actualUserAgent).isEqualTo(expectedUserAgent); |
| 47 | + } |
| 48 | +} |
0 commit comments