open-vault/helper/metricsutil/bucket_test.go
Mark Gritter 475fe0eede
Token creation counters (#9052)
* Add token creation counters.
* Created a utility to change TTL to bucket name.
* Add counter covering token creation for response wrapping.
* Fix namespace label, with a new utility function.
2020-06-02 13:40:54 -05:00

29 lines
574 B
Go

package metricsutil
import (
"testing"
"time"
)
func TestTTLBucket_Lookup(t *testing.T) {
testCases := []struct {
Input time.Duration
Expected string
}{
{30 * time.Second, "1m"},
{0 * time.Second, "1m"},
{2 * time.Hour, "2h"},
{2*time.Hour - time.Second, "2h"},
{2*time.Hour + time.Second, "1d"},
{30 * 24 * time.Hour, "30d"},
{31 * 24 * time.Hour, "+Inf"},
}
for _, tc := range testCases {
bucket := TTLBucket(tc.Input)
if bucket != tc.Expected {
t.Errorf("Expected %q, got %q for duration %v.", tc.Expected, bucket, tc.Input)
}
}
}