mirror of
https://github.com/hashicorp/vault.git
synced 2026-04-25 15:42:14 +02:00
Co-authored-by: divyaac <divya.chandrasekaran@hashicorp.com>
This commit is contained in:
parent
6674b4358a
commit
2ce86cb367
@ -58,7 +58,12 @@ func durationAdjustedCertificateCount(validitySeconds int64) float64 {
|
||||
validityHours := float64(validitySeconds) / 3600.0
|
||||
units := validityHours / standardDuration
|
||||
// Round to 4 decimal places
|
||||
return math.Round(units*10000) / 10000
|
||||
ret := math.Round(units*10000) / 10000
|
||||
if ret == 0.0 && validitySeconds > 0 {
|
||||
// Ensure we don't return 0.0, which would be interpreted as no billable units.
|
||||
return 0.0001
|
||||
}
|
||||
return ret
|
||||
}
|
||||
|
||||
type CertCountIncrementer interface {
|
||||
|
||||
@ -17,7 +17,7 @@ func Test_durationAdjustedCertificateCount(t *testing.T) {
|
||||
{
|
||||
name: "zero duration",
|
||||
validitySeconds: 0,
|
||||
want: 0.0,
|
||||
want: 0, // If the duration is zero, the normalized unit should be zero
|
||||
},
|
||||
{
|
||||
name: "1 hour",
|
||||
@ -72,12 +72,12 @@ func Test_durationAdjustedCertificateCount(t *testing.T) {
|
||||
{
|
||||
name: "very small duration - 1 second",
|
||||
validitySeconds: 1,
|
||||
want: 0.0, // 1/3600/730 = 0.00000038... rounds to 0.0
|
||||
want: 0.0001, // 1/3600/730 = 0.00000038... rounds to 0.0 but should return default minimum 0.0001
|
||||
},
|
||||
{
|
||||
name: "very small duration - 60 seconds",
|
||||
validitySeconds: 60,
|
||||
want: 0.0, // 60/3600/730 = 0.000023... rounds to 0.0
|
||||
want: 0.0001, // 60/3600/730 = 0.000023... rounds to 0.0 and should return default minimum 0.0001
|
||||
},
|
||||
{
|
||||
name: "very small duration - 600 seconds",
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user