|
|
@ -20,10 +20,10 @@ import (
|
|
|
|
"fmt"
|
|
|
|
"fmt"
|
|
|
|
"testing"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"k8s.io/api/core/v1"
|
|
|
|
apierrors "k8s.io/apimachinery/pkg/api/errors"
|
|
|
|
apierrors "k8s.io/apimachinery/pkg/api/errors"
|
|
|
|
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
|
|
|
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
|
|
|
"k8s.io/kubernetes/pkg/apis/core"
|
|
|
|
corev1 "k8s.io/client-go/kubernetes/typed/core/v1"
|
|
|
|
"k8s.io/kubernetes/pkg/client/clientset_generated/internalclientset/typed/core/internalversion"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
rspb "k8s.io/helm/pkg/proto/hapi/release"
|
|
|
|
rspb "k8s.io/helm/pkg/proto/hapi/release"
|
|
|
|
)
|
|
|
|
)
|
|
|
@ -76,14 +76,14 @@ func newTestFixtureCfgMaps(t *testing.T, releases ...*rspb.Release) *ConfigMaps
|
|
|
|
|
|
|
|
|
|
|
|
// MockConfigMapsInterface mocks a kubernetes ConfigMapsInterface
|
|
|
|
// MockConfigMapsInterface mocks a kubernetes ConfigMapsInterface
|
|
|
|
type MockConfigMapsInterface struct {
|
|
|
|
type MockConfigMapsInterface struct {
|
|
|
|
internalversion.ConfigMapInterface
|
|
|
|
corev1.ConfigMapInterface
|
|
|
|
|
|
|
|
|
|
|
|
objects map[string]*core.ConfigMap
|
|
|
|
objects map[string]*v1.ConfigMap
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Init initializes the MockConfigMapsInterface with the set of releases.
|
|
|
|
// Init initializes the MockConfigMapsInterface with the set of releases.
|
|
|
|
func (mock *MockConfigMapsInterface) Init(t *testing.T, releases ...*rspb.Release) {
|
|
|
|
func (mock *MockConfigMapsInterface) Init(t *testing.T, releases ...*rspb.Release) {
|
|
|
|
mock.objects = map[string]*core.ConfigMap{}
|
|
|
|
mock.objects = map[string]*v1.ConfigMap{}
|
|
|
|
|
|
|
|
|
|
|
|
for _, rls := range releases {
|
|
|
|
for _, rls := range releases {
|
|
|
|
objkey := testKey(rls.Name, rls.Version)
|
|
|
|
objkey := testKey(rls.Name, rls.Version)
|
|
|
@ -97,17 +97,17 @@ func (mock *MockConfigMapsInterface) Init(t *testing.T, releases ...*rspb.Releas
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Get returns the ConfigMap by name.
|
|
|
|
// Get returns the ConfigMap by name.
|
|
|
|
func (mock *MockConfigMapsInterface) Get(name string, options metav1.GetOptions) (*core.ConfigMap, error) {
|
|
|
|
func (mock *MockConfigMapsInterface) Get(name string, options metav1.GetOptions) (*v1.ConfigMap, error) {
|
|
|
|
object, ok := mock.objects[name]
|
|
|
|
object, ok := mock.objects[name]
|
|
|
|
if !ok {
|
|
|
|
if !ok {
|
|
|
|
return nil, apierrors.NewNotFound(core.Resource("tests"), name)
|
|
|
|
return nil, apierrors.NewNotFound(v1.Resource("tests"), name)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return object, nil
|
|
|
|
return object, nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// List returns the a of ConfigMaps.
|
|
|
|
// List returns the a of ConfigMaps.
|
|
|
|
func (mock *MockConfigMapsInterface) List(opts metav1.ListOptions) (*core.ConfigMapList, error) {
|
|
|
|
func (mock *MockConfigMapsInterface) List(opts metav1.ListOptions) (*v1.ConfigMapList, error) {
|
|
|
|
var list core.ConfigMapList
|
|
|
|
var list v1.ConfigMapList
|
|
|
|
for _, cfgmap := range mock.objects {
|
|
|
|
for _, cfgmap := range mock.objects {
|
|
|
|
list.Items = append(list.Items, *cfgmap)
|
|
|
|
list.Items = append(list.Items, *cfgmap)
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -115,20 +115,20 @@ func (mock *MockConfigMapsInterface) List(opts metav1.ListOptions) (*core.Config
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Create creates a new ConfigMap.
|
|
|
|
// Create creates a new ConfigMap.
|
|
|
|
func (mock *MockConfigMapsInterface) Create(cfgmap *core.ConfigMap) (*core.ConfigMap, error) {
|
|
|
|
func (mock *MockConfigMapsInterface) Create(cfgmap *v1.ConfigMap) (*v1.ConfigMap, error) {
|
|
|
|
name := cfgmap.ObjectMeta.Name
|
|
|
|
name := cfgmap.ObjectMeta.Name
|
|
|
|
if object, ok := mock.objects[name]; ok {
|
|
|
|
if object, ok := mock.objects[name]; ok {
|
|
|
|
return object, apierrors.NewAlreadyExists(core.Resource("tests"), name)
|
|
|
|
return object, apierrors.NewAlreadyExists(v1.Resource("tests"), name)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
mock.objects[name] = cfgmap
|
|
|
|
mock.objects[name] = cfgmap
|
|
|
|
return cfgmap, nil
|
|
|
|
return cfgmap, nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Update updates a ConfigMap.
|
|
|
|
// Update updates a ConfigMap.
|
|
|
|
func (mock *MockConfigMapsInterface) Update(cfgmap *core.ConfigMap) (*core.ConfigMap, error) {
|
|
|
|
func (mock *MockConfigMapsInterface) Update(cfgmap *v1.ConfigMap) (*v1.ConfigMap, error) {
|
|
|
|
name := cfgmap.ObjectMeta.Name
|
|
|
|
name := cfgmap.ObjectMeta.Name
|
|
|
|
if _, ok := mock.objects[name]; !ok {
|
|
|
|
if _, ok := mock.objects[name]; !ok {
|
|
|
|
return nil, apierrors.NewNotFound(core.Resource("tests"), name)
|
|
|
|
return nil, apierrors.NewNotFound(v1.Resource("tests"), name)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
mock.objects[name] = cfgmap
|
|
|
|
mock.objects[name] = cfgmap
|
|
|
|
return cfgmap, nil
|
|
|
|
return cfgmap, nil
|
|
|
@ -137,7 +137,7 @@ func (mock *MockConfigMapsInterface) Update(cfgmap *core.ConfigMap) (*core.Confi
|
|
|
|
// Delete deletes a ConfigMap by name.
|
|
|
|
// Delete deletes a ConfigMap by name.
|
|
|
|
func (mock *MockConfigMapsInterface) Delete(name string, opts *metav1.DeleteOptions) error {
|
|
|
|
func (mock *MockConfigMapsInterface) Delete(name string, opts *metav1.DeleteOptions) error {
|
|
|
|
if _, ok := mock.objects[name]; !ok {
|
|
|
|
if _, ok := mock.objects[name]; !ok {
|
|
|
|
return apierrors.NewNotFound(core.Resource("tests"), name)
|
|
|
|
return apierrors.NewNotFound(v1.Resource("tests"), name)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
delete(mock.objects, name)
|
|
|
|
delete(mock.objects, name)
|
|
|
|
return nil
|
|
|
|
return nil
|
|
|
@ -154,14 +154,14 @@ func newTestFixtureSecrets(t *testing.T, releases ...*rspb.Release) *Secrets {
|
|
|
|
|
|
|
|
|
|
|
|
// MockSecretsInterface mocks a kubernetes SecretsInterface
|
|
|
|
// MockSecretsInterface mocks a kubernetes SecretsInterface
|
|
|
|
type MockSecretsInterface struct {
|
|
|
|
type MockSecretsInterface struct {
|
|
|
|
internalversion.SecretInterface
|
|
|
|
corev1.SecretInterface
|
|
|
|
|
|
|
|
|
|
|
|
objects map[string]*core.Secret
|
|
|
|
objects map[string]*v1.Secret
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Init initializes the MockSecretsInterface with the set of releases.
|
|
|
|
// Init initializes the MockSecretsInterface with the set of releases.
|
|
|
|
func (mock *MockSecretsInterface) Init(t *testing.T, releases ...*rspb.Release) {
|
|
|
|
func (mock *MockSecretsInterface) Init(t *testing.T, releases ...*rspb.Release) {
|
|
|
|
mock.objects = map[string]*core.Secret{}
|
|
|
|
mock.objects = map[string]*v1.Secret{}
|
|
|
|
|
|
|
|
|
|
|
|
for _, rls := range releases {
|
|
|
|
for _, rls := range releases {
|
|
|
|
objkey := testKey(rls.Name, rls.Version)
|
|
|
|
objkey := testKey(rls.Name, rls.Version)
|
|
|
@ -175,17 +175,17 @@ func (mock *MockSecretsInterface) Init(t *testing.T, releases ...*rspb.Release)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Get returns the Secret by name.
|
|
|
|
// Get returns the Secret by name.
|
|
|
|
func (mock *MockSecretsInterface) Get(name string, options metav1.GetOptions) (*core.Secret, error) {
|
|
|
|
func (mock *MockSecretsInterface) Get(name string, options metav1.GetOptions) (*v1.Secret, error) {
|
|
|
|
object, ok := mock.objects[name]
|
|
|
|
object, ok := mock.objects[name]
|
|
|
|
if !ok {
|
|
|
|
if !ok {
|
|
|
|
return nil, apierrors.NewNotFound(core.Resource("tests"), name)
|
|
|
|
return nil, apierrors.NewNotFound(v1.Resource("tests"), name)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return object, nil
|
|
|
|
return object, nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// List returns the a of Secret.
|
|
|
|
// List returns the a of Secret.
|
|
|
|
func (mock *MockSecretsInterface) List(opts metav1.ListOptions) (*core.SecretList, error) {
|
|
|
|
func (mock *MockSecretsInterface) List(opts metav1.ListOptions) (*v1.SecretList, error) {
|
|
|
|
var list core.SecretList
|
|
|
|
var list v1.SecretList
|
|
|
|
for _, secret := range mock.objects {
|
|
|
|
for _, secret := range mock.objects {
|
|
|
|
list.Items = append(list.Items, *secret)
|
|
|
|
list.Items = append(list.Items, *secret)
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -193,20 +193,20 @@ func (mock *MockSecretsInterface) List(opts metav1.ListOptions) (*core.SecretLis
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Create creates a new Secret.
|
|
|
|
// Create creates a new Secret.
|
|
|
|
func (mock *MockSecretsInterface) Create(secret *core.Secret) (*core.Secret, error) {
|
|
|
|
func (mock *MockSecretsInterface) Create(secret *v1.Secret) (*v1.Secret, error) {
|
|
|
|
name := secret.ObjectMeta.Name
|
|
|
|
name := secret.ObjectMeta.Name
|
|
|
|
if object, ok := mock.objects[name]; ok {
|
|
|
|
if object, ok := mock.objects[name]; ok {
|
|
|
|
return object, apierrors.NewAlreadyExists(core.Resource("tests"), name)
|
|
|
|
return object, apierrors.NewAlreadyExists(v1.Resource("tests"), name)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
mock.objects[name] = secret
|
|
|
|
mock.objects[name] = secret
|
|
|
|
return secret, nil
|
|
|
|
return secret, nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Update updates a Secret.
|
|
|
|
// Update updates a Secret.
|
|
|
|
func (mock *MockSecretsInterface) Update(secret *core.Secret) (*core.Secret, error) {
|
|
|
|
func (mock *MockSecretsInterface) Update(secret *v1.Secret) (*v1.Secret, error) {
|
|
|
|
name := secret.ObjectMeta.Name
|
|
|
|
name := secret.ObjectMeta.Name
|
|
|
|
if _, ok := mock.objects[name]; !ok {
|
|
|
|
if _, ok := mock.objects[name]; !ok {
|
|
|
|
return nil, apierrors.NewNotFound(core.Resource("tests"), name)
|
|
|
|
return nil, apierrors.NewNotFound(v1.Resource("tests"), name)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
mock.objects[name] = secret
|
|
|
|
mock.objects[name] = secret
|
|
|
|
return secret, nil
|
|
|
|
return secret, nil
|
|
|
@ -215,7 +215,7 @@ func (mock *MockSecretsInterface) Update(secret *core.Secret) (*core.Secret, err
|
|
|
|
// Delete deletes a Secret by name.
|
|
|
|
// Delete deletes a Secret by name.
|
|
|
|
func (mock *MockSecretsInterface) Delete(name string, opts *metav1.DeleteOptions) error {
|
|
|
|
func (mock *MockSecretsInterface) Delete(name string, opts *metav1.DeleteOptions) error {
|
|
|
|
if _, ok := mock.objects[name]; !ok {
|
|
|
|
if _, ok := mock.objects[name]; !ok {
|
|
|
|
return apierrors.NewNotFound(core.Resource("tests"), name)
|
|
|
|
return apierrors.NewNotFound(v1.Resource("tests"), name)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
delete(mock.objects, name)
|
|
|
|
delete(mock.objects, name)
|
|
|
|
return nil
|
|
|
|
return nil
|
|
|
|