open-vault/api/renewer_test.go
Jeff Mitchell 90248c79b2
Update lease renewer logic (#4090)
* Add grace period calculation logic to renewer

* Update lease renewer logic.

It is believed by myself and members of the Nomad team that this logic
should be much more robust in terms of causing large numbers of new
secret acquisitions caused by a static grace period. See comments in the
code for details.

Fixes #3414

* Fix some commenting and fix tests

* Add more time to test so that integ tests don't time out

* Fix some review feedback
2018-03-19 15:48:24 -04:00

85 lines
1.1 KiB
Go

package api
import (
"reflect"
"testing"
"time"
)
func TestRenewer_NewRenewer(t *testing.T) {
t.Parallel()
client, err := NewClient(DefaultConfig())
if err != nil {
t.Fatal(err)
}
cases := []struct {
name string
i *RenewerInput
e *Renewer
err bool
}{
{
"nil",
nil,
nil,
true,
},
{
"missing_secret",
&RenewerInput{
Secret: nil,
},
nil,
true,
},
{
"default_grace",
&RenewerInput{
Secret: &Secret{},
},
&Renewer{
secret: &Secret{},
},
false,
},
{
"custom_grace",
&RenewerInput{
Secret: &Secret{},
Grace: 30 * time.Second,
},
&Renewer{
secret: &Secret{},
grace: 30 * time.Second,
},
false,
},
}
for _, tc := range cases {
t.Run(tc.name, func(t *testing.T) {
v, err := client.NewRenewer(tc.i)
if (err != nil) != tc.err {
t.Fatal(err)
}
if v == nil {
return
}
// Zero-out channels because reflect
v.client = nil
v.random = nil
v.doneCh = nil
v.renewCh = nil
v.stopCh = nil
if !reflect.DeepEqual(tc.e, v) {
t.Errorf("not equal\nexp: %#v\nact: %#v", tc.e, v)
}
})
}
}