Skip to content

Commit

Permalink
Merge pull request #86 from gmaliar/lease-duration-fix
Browse files Browse the repository at this point in the history
fix lease duration of one second
  • Loading branch information
gambol99 committed Mar 5, 2019
2 parents 41e729c + b0b2c12 commit 784383a
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
6 changes: 5 additions & 1 deletion utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,11 @@ func readYAMLFile(filename string) (*vaultAuthOptions, error) {
// min : the smallest number we can accept
// max : the largest number we can accept
func getDurationWithin(min, max int) time.Duration {
duration := rand.Intn(max-min) + min
jitter := max - min
if jitter <= 0 {
jitter = 1
}
duration := rand.Intn(jitter) + min
return time.Duration(duration) * time.Second
}

Expand Down
8 changes: 8 additions & 0 deletions utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,3 +113,11 @@ func TestReadConfigTokenYAML(t *testing.T) {
t.Errorf("Expected token %s got %s", expected, o.Token)
}
}

func TestGetDurationWithin(t *testing.T) {
duration := getDurationWithin(1, 1)

if duration <= 0 {
t.Errorf("Expected duration to be higher than 0 got %d", duration)
}
}

0 comments on commit 784383a

Please sign in to comment.