|
| 1 | +/* |
| 2 | +SPDX-FileCopyrightText: Copyright (c) NVIDIA CORPORATION & AFFILIATES. All rights reserved. |
| 3 | +SPDX-License-Identifier: Apache-2.0 |
| 4 | +
|
| 5 | +Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | +you may not use this file except in compliance with the License. |
| 7 | +You may obtain a copy of the License at |
| 8 | +
|
| 9 | + http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | +
|
| 11 | +Unless required by applicable law or agreed to in writing, software |
| 12 | +distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | +See the License for the specific language governing permissions and |
| 15 | +limitations under the License. |
| 16 | +*/ |
| 17 | + |
| 18 | +// Package main - stamped metadata tests. |
| 19 | +// This file is compiled by the cmd_info_stamped_test Bazel target, which |
| 20 | +// injects known x_defs for Service, Version, and GitHash so the assertions |
| 21 | +// can verify the exact values rather than the "unknown" fallback. |
| 22 | +package main |
| 23 | + |
| 24 | +import ( |
| 25 | + "encoding/json" |
| 26 | + "net/http" |
| 27 | + "net/http/httptest" |
| 28 | + "testing" |
| 29 | + |
| 30 | + golibversion "github.com/NVIDIA/nvcf/src/libraries/go/lib/pkg/version" |
| 31 | + |
| 32 | + "github.com/stretchr/testify/assert" |
| 33 | + "github.com/stretchr/testify/require" |
| 34 | +) |
| 35 | + |
| 36 | +func TestNewHealthServeMux_Info_StampedValues(t *testing.T) { |
| 37 | + if golibversion.Version == "" { |
| 38 | + t.Skip("x_defs not injected; run via bazel test :cmd_info_stamped_test") |
| 39 | + } |
| 40 | + |
| 41 | + mux := newHealthServeMux(nil) |
| 42 | + require.NotNil(t, mux) |
| 43 | + |
| 44 | + w := httptest.NewRecorder() |
| 45 | + r := httptest.NewRequest(http.MethodGet, "/info", nil) |
| 46 | + mux.ServeHTTP(w, r) |
| 47 | + |
| 48 | + require.Equal(t, http.StatusOK, w.Code) |
| 49 | + require.Equal(t, "application/json", w.Header().Get("Content-Type")) |
| 50 | + |
| 51 | + var info map[string]string |
| 52 | + require.NoError(t, json.Unmarshal(w.Body.Bytes(), &info)) |
| 53 | + assert.Equal(t, "nvcf-ratelimiter", info["service"]) |
| 54 | + assert.Equal(t, "test-1.0.0", info["version"]) |
| 55 | + assert.Equal(t, "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", info["commit"]) |
| 56 | +} |
0 commit comments