Skip to content

Commit 89ac3ec

Browse files
test(ratelimiter): expand /info test coverage and add stamped x_defs test
Signed-off-by: priyaselvaganesan <pselvaganesa@nvidia.com>
1 parent 2be212a commit 89ac3ec

3 files changed

Lines changed: 79 additions & 1 deletion

File tree

‎src/invocation-plane-services/ratelimiter/cmd/BUILD.bazel‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,3 +101,18 @@ go_test(
101101
"@org_uber_go_zap//:zap",
102102
],
103103
)
104+
105+
go_test(
106+
name = "cmd_info_stamped_test",
107+
srcs = ["info_stamped_test.go"],
108+
embed = [":cmd_lib"],
109+
x_defs = {
110+
"github.com/NVIDIA/nvcf/src/libraries/go/lib/pkg/version.Service": "nvcf-ratelimiter",
111+
"github.com/NVIDIA/nvcf/src/libraries/go/lib/pkg/version.Version": "test-1.0.0",
112+
"github.com/NVIDIA/nvcf/src/libraries/go/lib/pkg/version.GitHash": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
113+
},
114+
deps = [
115+
"@com_github_stretchr_testify//assert",
116+
"@com_github_stretchr_testify//require",
117+
],
118+
)
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
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+
}

‎src/invocation-plane-services/ratelimiter/cmd/info_test.go‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,14 @@ func TestNewHealthServeMux_Info_RejectsNonGET(t *testing.T) {
5555
mux := newHealthServeMux(nil)
5656
require.NotNil(t, mux)
5757

58-
for _, method := range []string{http.MethodPost, http.MethodPut, http.MethodDelete} {
58+
for _, method := range []string{
59+
http.MethodHead,
60+
http.MethodPost,
61+
http.MethodPut,
62+
http.MethodPatch,
63+
http.MethodDelete,
64+
http.MethodOptions,
65+
} {
5966
t.Run(method, func(t *testing.T) {
6067
w := httptest.NewRecorder()
6168
r := httptest.NewRequest(method, "/info", nil)

0 commit comments

Comments
 (0)