feat(go): add capacity health check tool

This commit is contained in:
lingniu
2026-07-03 19:54:29 +08:00
parent 68b729fa7b
commit 3edd7462c7
6 changed files with 349 additions and 0 deletions

View File

@@ -0,0 +1,31 @@
package main
import (
"strings"
"testing"
)
func TestParseEndpoints(t *testing.T) {
endpoints := parseEndpoints("gateway=http://127.0.0.1:20211/metrics, fast=http://127.0.0.1:20215/metrics")
if len(endpoints) != 2 {
t.Fatalf("len = %d, want 2: %#v", len(endpoints), endpoints)
}
if endpoints[0].Name != "gateway" || endpoints[0].URL != "http://127.0.0.1:20211/metrics" {
t.Fatalf("endpoint[0] = %#v", endpoints[0])
}
if endpoints[1].Name != "fast" || endpoints[1].URL != "http://127.0.0.1:20215/metrics" {
t.Fatalf("endpoint[1] = %#v", endpoints[1])
}
}
func TestParseEndpointsUsesDefaultMetricsURLWhenOnlyBaseURLIsProvided(t *testing.T) {
endpoints := parseEndpoints("gateway=http://127.0.0.1:20211")
if len(endpoints) != 1 {
t.Fatalf("len = %d, want 1", len(endpoints))
}
if !strings.HasSuffix(endpoints[0].URL, "/metrics") {
t.Fatalf("url = %q, want /metrics suffix", endpoints[0].URL)
}
}