| 1 | package common |
| 2 | |
| 3 | import "testing" |
| 4 | |
| 5 | func TestIdentityLabels(t *testing.T) { |
| 6 | id := Identity{Cluster: "prod", Cell: "appcell", Node: "node1", Server: "server1", Edition: "traditional", Version: "9.0.5"} |
| 7 | labels := id.Labels() |
| 8 | if labels["cluster"] != "prod" || labels["websphere_version"] != "9.0.5" { |
| 9 | t.Fatalf("unexpected labels: %#v", labels) |
| 10 | } |
| 11 | } |
| 12 | |
| 13 | func TestNormaliseName(t *testing.T) { |
| 14 | cases := map[string]string{ |
| 15 | "Web Container": "web_container", |
| 16 | "$$$": "unknown", |
| 17 | "http-server": "http_server", |
| 18 | } |
| 19 | for input, expect := range cases { |
| 20 | if got := NormaliseName(input); got != expect { |
| 21 | t.Fatalf("normalise %q: got %q expect %q", input, got, expect) |
| 22 | } |
| 23 | } |
| 24 | } |
| 25 | |
| 26 | func TestInstanceKey(t *testing.T) { |
| 27 | if key := InstanceKey("Node01", "Server1", "Thread Pool"); key != "node01.server1.thread_pool" { |
| 28 | t.Fatalf("unexpected key: %s", key) |
| 29 | } |
| 30 | } |
| 31 | |
| 32 | func TestFormatPercent(t *testing.T) { |
| 33 | if val := FormatPercent(12.345); val != 12345 { |
| 34 | t.Fatalf("unexpected percent value: %d", val) |
| 35 | } |
| 36 | } |
| 37 | |
| 38 | func TestBuildMetricName(t *testing.T) { |
| 39 | if name := BuildMetricName("JVM", "Heap Usage"); name != "jvm.heap_usage" { |
| 40 | t.Fatalf("unexpected metric name: %s", name) |
| 41 | } |
| 42 | } |