github.com/lyft/flytestdlib@v0.3.12-0.20210213045714-8cdd111ecda1/promutils/labeled/counter_test.go (about) 1 package labeled 2 3 import ( 4 "context" 5 "testing" 6 7 "github.com/lyft/flytestdlib/contextutils" 8 "github.com/lyft/flytestdlib/promutils" 9 "github.com/stretchr/testify/assert" 10 ) 11 12 func TestLabeledCounter(t *testing.T) { 13 UnsetMetricKeys() 14 assert.NotPanics(t, func() { 15 SetMetricKeys(contextutils.ProjectKey, contextutils.DomainKey, contextutils.WorkflowIDKey, contextutils.TaskIDKey, contextutils.LaunchPlanIDKey) 16 }) 17 18 scope := promutils.NewTestScope() 19 c := NewCounter("lbl_counter", "help", scope) 20 assert.NotNil(t, c) 21 ctx := context.TODO() 22 c.Inc(ctx) 23 c.Add(ctx, 1.0) 24 25 ctx = contextutils.WithProjectDomain(ctx, "project", "domain") 26 c.Inc(ctx) 27 c.Add(ctx, 1.0) 28 29 ctx = contextutils.WithTaskID(ctx, "task") 30 c.Inc(ctx) 31 c.Add(ctx, 1.0) 32 33 ctx = contextutils.WithLaunchPlanID(ctx, "lp") 34 c.Inc(ctx) 35 c.Add(ctx, 1.0) 36 }