open-vault/helper/metricsutil/bucket_test.go
Hamid Ghaf 27bb03bbc0
adding copyright header (#19555)
* adding copyright header

* fix fmt and a test
2023-03-15 09:00:52 -07:00

32 lines
644 B
Go

// Copyright (c) HashiCorp, Inc.
// SPDX-License-Identifier: MPL-2.0
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)
}
}
}