github.com/puellanivis/breton@v0.2.16/lib/metrics/counter_test.go (about)

     1  package metrics
     2  
     3  import (
     4  	"math"
     5  	"testing"
     6  )
     7  
     8  const (
     9  	LabelFoo       = Label("foo")
    10  	LabelBar       = Label("bar")
    11  	LabelInvalid   = Label("invalid!")
    12  	LabelUndefined = Label("undefined")
    13  )
    14  
    15  func TestCounter(t *testing.T) {
    16  	labels := []Labeler{
    17  		LabelFoo.WithValue("default"),
    18  		LabelBar.Const("stuff"),
    19  		//LabelInvalid,
    20  	}
    21  
    22  	_ = LabelInvalid // use label in case it is commented above
    23  
    24  	c := Counter("test", "testing counter", WithLabels(labels...))
    25  
    26  	c.WithLabels(LabelFoo.WithValue("things")).Inc()
    27  	c.WithLabels(LabelFoo.WithValue("stuff")).Add(42)
    28  	c.WithLabels().Add(math.Pi)
    29  
    30  	// all of these commented “tests“ are “undefined behavior”
    31  	// as such actually testing for their behavior would define
    32  	// their behavior, which is not the proper way to write tests.
    33  
    34  	//c.WithLabels(LabelBar.WithValue("constant!")).Add(math.E)
    35  	//c.WithLabels(LabelUndefined.WithValue("undefined!")).Add(math.Phi)
    36  	//c.WithLabels(LabelUndefined).Add(math.Phi)
    37  
    38  	_ = LabelUndefined // use label in case it is commented above
    39  
    40  	t.Logf("counter: %#v", c)
    41  	t.Logf("labels: %#v", c.labels.getList())
    42  	t.Logf("labelset: %#v", c.labels.set)
    43  	t.Logf("helpString: %q", c.helpString())
    44  }