diff --git a/prometheus_test.go b/prometheus_test.go index e0b357a..ffb63a1 100644 --- a/prometheus_test.go +++ b/prometheus_test.go @@ -2,6 +2,7 @@ package prometheus import ( "bytes" + "fmt" "testing" "go.unistack.org/micro/v4/meter" @@ -49,3 +50,27 @@ func TestMultiple(t *testing.T) { t.Fatalf("invalid metrics output: %s", buf.Bytes()) } } + +func TestCounterSet(t *testing.T) { + m := NewMeter() + + value := uint64(42) + + m.Counter("forte_accounts_total", "channel_code", "crm").Set(value) + + fmt.Println(uint64(float64(value))) + + buf := bytes.NewBuffer(nil) + + _ = m.Write(buf) + + output := buf.String() + + fmt.Println(output) + + expectedOutput := fmt.Sprintf(`%s{channel_code="crm"} %d`, "forte_accounts_total", value) + + if !bytes.Contains(buf.Bytes(), []byte(expectedOutput)) { + t.Fatalf("invalid metrics output: expected %q, got %q", expectedOutput, output) + } +}