Skip to content

Commit 17efbda

Browse files
richabankerk8s-publishing-bot
authored andcommitted
Add tests
Kubernetes-commit: 19ebee96b2cf7cb5163e33ac27725b74f3536633
1 parent bbbee38 commit 17efbda

File tree

1 file changed

+44
-0
lines changed

1 file changed

+44
-0
lines changed
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/*
2+
Copyright 2024 The Kubernetes Authors.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package slis
18+
19+
import (
20+
"net/http"
21+
"testing"
22+
23+
"github.com/stretchr/testify/assert"
24+
)
25+
26+
type mockMux struct {
27+
handledPaths []string
28+
}
29+
30+
func (m *mockMux) Handle(path string, handler http.Handler) {
31+
m.handledPaths = append(m.handledPaths, path)
32+
}
33+
34+
func TestSLIMetrics_Install(t *testing.T) {
35+
m := &mockMux{}
36+
s := SLIMetrics{}
37+
38+
s.Install(m)
39+
assert.Equal(t, []string{"/metrics/slis"}, m.handledPaths)
40+
41+
s.Install(m)
42+
// Assert that the path is registered twice for the 2 calls made to Install().
43+
assert.Equal(t, []string{"/metrics/slis", "/metrics/slis"}, m.handledPaths, "Should handle the path twice.")
44+
}

0 commit comments

Comments
 (0)