Skip to content

Commit

Permalink
adv ttl mgmt: refactor window tests (#22472)
Browse files Browse the repository at this point in the history
  • Loading branch information
fairclothjm authored Aug 21, 2023
1 parent 3b02e00 commit 5a3a154
Showing 1 changed file with 5 additions and 14 deletions.
19 changes: 5 additions & 14 deletions builtin/logical/database/path_roles_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -904,12 +904,6 @@ func TestWALsDeletedOnRoleDeletion(t *testing.T) {
}

func TestIsInsideRotationWindow(t *testing.T) {
rotationPeriodData := map[string]interface{}{
"username": "hashicorp",
"db_name": "mockv5",
"rotation_period": "86400s",
}

for _, tc := range []struct {
name string
expected bool
Expand All @@ -920,16 +914,16 @@ func TestIsInsideRotationWindow(t *testing.T) {
{
"always returns true for rotation_period type",
true,
rotationPeriodData,
map[string]interface{}{
"rotation_period": "86400s",
},
time.Now(),
nil,
},
{
"always returns true for rotation_schedule when no rotation_window set",
true,
map[string]interface{}{
"username": "hashicorp",
"db_name": "mockv5",
"rotation_schedule": "0 0 */2 * * *",
},
time.Now(),
Expand All @@ -939,8 +933,6 @@ func TestIsInsideRotationWindow(t *testing.T) {
"returns true for rotation_schedule when inside rotation_window",
true,
map[string]interface{}{
"username": "hashicorp",
"db_name": "mockv5",
"rotation_schedule": "0 0 */2 * * *",
"rotation_window": "3600s",
},
Expand All @@ -954,8 +946,6 @@ func TestIsInsideRotationWindow(t *testing.T) {
"returns false for rotation_schedule when outside rotation_window",
false,
map[string]interface{}{
"username": "hashicorp",
"db_name": "mockv5",
"rotation_schedule": "0 0 */2 * * *",
"rotation_window": "3600s",
},
Expand Down Expand Up @@ -988,13 +978,14 @@ func TestIsInsideRotationWindow(t *testing.T) {
testTime = tc.timeModifier(next2)
}

tc.data["username"] = "hashicorp"
tc.data["db_name"] = "mockv5"
createRoleWithData(t, b, s, mockDB, "test-role", tc.data)
role, err := b.StaticRole(ctx, s, "test-role")
if err != nil {
t.Fatal(err)
}

// testTime := sched.Next(time.Now()).tc.timeModifier()
isInsideWindow := role.StaticAccount.IsInsideRotationWindow(testTime)
if tc.expected != isInsideWindow {
t.Fatalf("expected %t, got %t", tc.expected, isInsideWindow)
Expand Down

0 comments on commit 5a3a154

Please sign in to comment.