|
|
|
@ -20,10 +20,10 @@ import (
|
|
|
|
|
"fmt"
|
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
|
|
"k8s.io/api/core/v1"
|
|
|
|
|
apierrors "k8s.io/apimachinery/pkg/api/errors"
|
|
|
|
|
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
|
|
|
|
"k8s.io/kubernetes/pkg/apis/core"
|
|
|
|
|
"k8s.io/kubernetes/pkg/client/clientset_generated/internalclientset/typed/core/internalversion"
|
|
|
|
|
corev1 "k8s.io/client-go/kubernetes/typed/core/v1"
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
|
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.
|
|
|
|
|
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 {
|
|
|
|
|
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.
|
|
|
|
|
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]
|
|
|
|
|
if !ok {
|
|
|
|
|
return nil, apierrors.NewNotFound(core.Resource("tests"), name)
|
|
|
|
|
return nil, apierrors.NewNotFound(v1.Resource("tests"), name)
|
|
|
|
|
}
|
|
|
|
|
return object, nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// List returns the a of ConfigMaps.
|
|
|
|
|
func (mock *MockConfigMapsInterface) List(opts metav1.ListOptions) (*core.ConfigMapList, error) {
|
|
|
|
|
var list core.ConfigMapList
|
|
|
|
|
func (mock *MockConfigMapsInterface) List(opts metav1.ListOptions) (*v1.ConfigMapList, error) {
|
|
|
|
|
var list v1.ConfigMapList
|
|
|
|
|
for _, cfgmap := range mock.objects {
|
|
|
|
|
list.Items = append(list.Items, *cfgmap)
|
|
|
|
|
}
|
|
|
|
@ -115,20 +115,20 @@ func (mock *MockConfigMapsInterface) List(opts metav1.ListOptions) (*core.Config
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 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
|
|
|
|
|
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
|
|
|
|
|
return cfgmap, nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 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
|
|
|
|
|
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
|
|
|
|
|
return cfgmap, nil
|
|
|
|
@ -137,7 +137,7 @@ func (mock *MockConfigMapsInterface) Update(cfgmap *core.ConfigMap) (*core.Confi
|
|
|
|
|
// Delete deletes a ConfigMap by name.
|
|
|
|
|
func (mock *MockConfigMapsInterface) Delete(name string, opts *metav1.DeleteOptions) error {
|
|
|
|
|
if _, ok := mock.objects[name]; !ok {
|
|
|
|
|
return apierrors.NewNotFound(core.Resource("tests"), name)
|
|
|
|
|
return apierrors.NewNotFound(v1.Resource("tests"), name)
|
|
|
|
|
}
|
|
|
|
|
delete(mock.objects, name)
|
|
|
|
|
return nil
|
|
|
|
@ -154,14 +154,14 @@ func newTestFixtureSecrets(t *testing.T, releases ...*rspb.Release) *Secrets {
|
|
|
|
|
|
|
|
|
|
// MockSecretsInterface mocks a kubernetes SecretsInterface
|
|
|
|
|
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.
|
|
|
|
|
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 {
|
|
|
|
|
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.
|
|
|
|
|
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]
|
|
|
|
|
if !ok {
|
|
|
|
|
return nil, apierrors.NewNotFound(core.Resource("tests"), name)
|
|
|
|
|
return nil, apierrors.NewNotFound(v1.Resource("tests"), name)
|
|
|
|
|
}
|
|
|
|
|
return object, nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// List returns the a of Secret.
|
|
|
|
|
func (mock *MockSecretsInterface) List(opts metav1.ListOptions) (*core.SecretList, error) {
|
|
|
|
|
var list core.SecretList
|
|
|
|
|
func (mock *MockSecretsInterface) List(opts metav1.ListOptions) (*v1.SecretList, error) {
|
|
|
|
|
var list v1.SecretList
|
|
|
|
|
for _, secret := range mock.objects {
|
|
|
|
|
list.Items = append(list.Items, *secret)
|
|
|
|
|
}
|
|
|
|
@ -193,20 +193,20 @@ func (mock *MockSecretsInterface) List(opts metav1.ListOptions) (*core.SecretLis
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 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
|
|
|
|
|
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
|
|
|
|
|
return secret, nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 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
|
|
|
|
|
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
|
|
|
|
|
return secret, nil
|
|
|
|
@ -215,7 +215,7 @@ func (mock *MockSecretsInterface) Update(secret *core.Secret) (*core.Secret, err
|
|
|
|
|
// Delete deletes a Secret by name.
|
|
|
|
|
func (mock *MockSecretsInterface) Delete(name string, opts *metav1.DeleteOptions) error {
|
|
|
|
|
if _, ok := mock.objects[name]; !ok {
|
|
|
|
|
return apierrors.NewNotFound(core.Resource("tests"), name)
|
|
|
|
|
return apierrors.NewNotFound(v1.Resource("tests"), name)
|
|
|
|
|
}
|
|
|
|
|
delete(mock.objects, name)
|
|
|
|
|
return nil
|
|
|
|
|