2017-06-20 04:34:11 +00:00
|
|
|
package api
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
2019-10-29 00:28:59 +00:00
|
|
|
|
|
|
|
"github.com/go-test/deep"
|
2017-06-20 04:34:11 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
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,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2017-06-26 21:21:37 +00:00
|
|
|
for _, tc := range cases {
|
|
|
|
t.Run(tc.name, func(t *testing.T) {
|
2017-06-20 04:34:11 +00:00
|
|
|
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
|
2017-06-29 00:38:03 +00:00
|
|
|
v.random = nil
|
2017-06-20 04:34:11 +00:00
|
|
|
v.doneCh = nil
|
2017-06-26 21:21:37 +00:00
|
|
|
v.renewCh = nil
|
2017-06-20 04:34:11 +00:00
|
|
|
v.stopCh = nil
|
|
|
|
|
2019-10-29 00:28:59 +00:00
|
|
|
if diff := deep.Equal(tc.e, v); diff != nil {
|
|
|
|
t.Error(diff)
|
2017-06-20 04:34:11 +00:00
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|