You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
56 lines
1.3 KiB
Go
56 lines
1.3 KiB
Go
5 years ago
|
package provisioner
|
||
6 years ago
|
|
||
|
import (
|
||
|
"errors"
|
||
|
"testing"
|
||
|
|
||
|
"github.com/smallstep/assert"
|
||
|
jose "gopkg.in/square/go-jose.v2"
|
||
|
)
|
||
|
|
||
6 years ago
|
func TestProvisionerInit(t *testing.T) {
|
||
6 years ago
|
type ProvisionerValidateTest struct {
|
||
|
p *Provisioner
|
||
|
err error
|
||
|
}
|
||
|
tests := map[string]func(*testing.T) ProvisionerValidateTest{
|
||
6 years ago
|
"fail-empty-name": func(t *testing.T) ProvisionerValidateTest {
|
||
6 years ago
|
return ProvisionerValidateTest{
|
||
|
p: &Provisioner{},
|
||
6 years ago
|
err: errors.New("provisioner name cannot be empty"),
|
||
6 years ago
|
}
|
||
|
},
|
||
|
"fail-empty-type": func(t *testing.T) ProvisionerValidateTest {
|
||
|
return ProvisionerValidateTest{
|
||
6 years ago
|
p: &Provisioner{Name: "foo"},
|
||
6 years ago
|
err: errors.New("provisioner type cannot be empty"),
|
||
|
}
|
||
|
},
|
||
|
"fail-empty-key": func(t *testing.T) ProvisionerValidateTest {
|
||
|
return ProvisionerValidateTest{
|
||
6 years ago
|
p: &Provisioner{Name: "foo", Type: "bar"},
|
||
6 years ago
|
err: errors.New("provisioner key cannot be empty"),
|
||
|
}
|
||
|
},
|
||
|
"ok": func(t *testing.T) ProvisionerValidateTest {
|
||
|
return ProvisionerValidateTest{
|
||
6 years ago
|
p: &Provisioner{Name: "foo", Type: "bar", Key: &jose.JSONWebKey{}},
|
||
6 years ago
|
}
|
||
|
},
|
||
|
}
|
||
|
|
||
|
for name, get := range tests {
|
||
|
t.Run(name, func(t *testing.T) {
|
||
|
tc := get(t)
|
||
6 years ago
|
err := tc.p.Init(&globalProvisionerClaims)
|
||
6 years ago
|
if err != nil {
|
||
|
if assert.NotNil(t, tc.err) {
|
||
|
assert.Equals(t, tc.err.Error(), err.Error())
|
||
|
}
|
||
|
} else {
|
||
|
assert.Nil(t, tc.err)
|
||
|
}
|
||
|
})
|
||
|
}
|
||
|
}
|