Skip to content

Commit db15a2f

Browse files
committed
Use in IPInfo map to test shadowsocks_ip_key_connectivity_seconds_per_location.
1 parent fb7bc2e commit db15a2f

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

cmd/outline-ss-server/metrics_test.go

+9-2
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
package main
1616

1717
import (
18+
"net"
1819
"strings"
1920
"testing"
2021
"time"
@@ -26,6 +27,12 @@ import (
2627
"github.com/stretchr/testify/require"
2728
)
2829

30+
type noopMap struct{}
31+
32+
func (*noopMap) GetIPInfo(ip net.IP) (ipinfo.IPInfo, error) {
33+
return ipinfo.IPInfo{}, nil
34+
}
35+
2936
type fakeAddr string
3037

3138
func (a fakeAddr) String() string { return string(a) }
@@ -109,7 +116,7 @@ func TestIPKeyActivityPerKey(t *testing.T) {
109116
func TestIPKeyActivityPerLocation(t *testing.T) {
110117
since = func(time.Time) time.Duration { return 5 * time.Second }
111118
reg := prometheus.NewPedanticRegistry()
112-
ssMetrics := newPrometheusOutlineMetrics(nil, reg)
119+
ssMetrics := newPrometheusOutlineMetrics(&noopMap{}, reg)
113120
accessKey := "key-1"
114121
status := "OK"
115122
data := metrics.ProxyMetrics{}
@@ -121,7 +128,7 @@ func TestIPKeyActivityPerLocation(t *testing.T) {
121128
expected := strings.NewReader(`
122129
# HELP shadowsocks_ip_key_connectivity_seconds_per_location Time at least 1 connection was open for a (IP, access key) pair, per location
123130
# TYPE shadowsocks_ip_key_connectivity_seconds_per_location counter
124-
shadowsocks_ip_key_connectivity_seconds_per_location{asn="",location=""} 5
131+
shadowsocks_ip_key_connectivity_seconds_per_location{asn="",location="XL"} 5
125132
`)
126133
err := promtest.GatherAndCompare(
127134
reg,

0 commit comments

Comments
 (0)