Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor ent controller tests #342

Merged
merged 3 commits into from
Sep 30, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions api/v1alpha1/proxydefaults_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (

// +kubebuilder:object:generate=false

type ProxyDefaultsValidator struct {
type ProxyDefaultsWebhook struct {
client.Client
ConsulClient *capi.Client
Logger logr.Logger
Expand All @@ -33,7 +33,7 @@ type ProxyDefaultsValidator struct {
//
// +kubebuilder:webhook:verbs=create;update,path=/mutate-v1alpha1-proxydefaults,mutating=true,failurePolicy=fail,groups=consul.hashicorp.com,resources=proxydefaults,versions=v1alpha1,name=mutate-proxydefaults.consul.hashicorp.com,webhookVersions=v1beta1,sideEffects=None

func (v *ProxyDefaultsValidator) Handle(ctx context.Context, req admission.Request) admission.Response {
func (v *ProxyDefaultsWebhook) Handle(ctx context.Context, req admission.Request) admission.Response {
var proxyDefaults ProxyDefaults
var proxyDefaultsList ProxyDefaultsList
err := v.decoder.Decode(req, &proxyDefaults)
Expand Down Expand Up @@ -67,7 +67,7 @@ func (v *ProxyDefaultsValidator) Handle(ctx context.Context, req admission.Reque
return admission.Allowed(fmt.Sprintf("valid %s request", proxyDefaults.KubeKind()))
}

func (v *ProxyDefaultsValidator) InjectDecoder(d *admission.Decoder) error {
func (v *ProxyDefaultsWebhook) InjectDecoder(d *admission.Decoder) error {
v.decoder = d
return nil
}
2 changes: 1 addition & 1 deletion api/v1alpha1/proxydefaults_webhook_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ func TestValidateConfigEntry(t *testing.T) {
decoder, err := admission.NewDecoder(s)
require.NoError(t, err)

validator := &ProxyDefaultsValidator{
validator := &ProxyDefaultsWebhook{
Client: client,
ConsulClient: nil,
Logger: logrtest.TestLogger{T: t},
Expand Down
8 changes: 4 additions & 4 deletions api/v1alpha1/servicedefaults_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (

// +kubebuilder:object:generate=false

type ServiceDefaultsValidator struct {
type ServiceDefaultsWebhook struct {
ConsulClient *capi.Client
Logger logr.Logger

Expand All @@ -38,7 +38,7 @@ type ServiceDefaultsValidator struct {
//
// +kubebuilder:webhook:verbs=create;update,path=/mutate-v1alpha1-servicedefaults,mutating=true,failurePolicy=fail,groups=consul.hashicorp.com,resources=servicedefaults,versions=v1alpha1,name=mutate-servicedefaults.consul.hashicorp.com,webhookVersions=v1beta1,sideEffects=None

func (v *ServiceDefaultsValidator) Handle(ctx context.Context, req admission.Request) admission.Response {
func (v *ServiceDefaultsWebhook) Handle(ctx context.Context, req admission.Request) admission.Response {
var svcDefaults ServiceDefaults
err := v.decoder.Decode(req, &svcDefaults)
if err != nil {
Expand All @@ -54,7 +54,7 @@ func (v *ServiceDefaultsValidator) Handle(ctx context.Context, req admission.Req
v.EnableNSMirroring)
}

func (v *ServiceDefaultsValidator) List(ctx context.Context) ([]common.ConfigEntryResource, error) {
func (v *ServiceDefaultsWebhook) List(ctx context.Context) ([]common.ConfigEntryResource, error) {
var svcDefaultsList ServiceDefaultsList
if err := v.Client.List(ctx, &svcDefaultsList); err != nil {
return nil, err
Expand All @@ -66,7 +66,7 @@ func (v *ServiceDefaultsValidator) List(ctx context.Context) ([]common.ConfigEnt
return entries, nil
}

func (v *ServiceDefaultsValidator) InjectDecoder(d *admission.Decoder) error {
func (v *ServiceDefaultsWebhook) InjectDecoder(d *admission.Decoder) error {
v.decoder = d
return nil
}
8 changes: 4 additions & 4 deletions api/v1alpha1/serviceresolver_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (

// +kubebuilder:object:generate=false

type ServiceResolverValidator struct {
type ServiceResolverWebhook struct {
ConsulClient *capi.Client
Logger logr.Logger

Expand All @@ -38,7 +38,7 @@ type ServiceResolverValidator struct {
//
// +kubebuilder:webhook:verbs=create;update,path=/mutate-v1alpha1-serviceresolver,mutating=true,failurePolicy=fail,groups=consul.hashicorp.com,resources=serviceresolvers,versions=v1alpha1,name=mutate-serviceresolver.consul.hashicorp.com,webhookVersions=v1beta1,sideEffects=None

func (v *ServiceResolverValidator) Handle(ctx context.Context, req admission.Request) admission.Response {
func (v *ServiceResolverWebhook) Handle(ctx context.Context, req admission.Request) admission.Response {
var svcResolver ServiceResolver
err := v.decoder.Decode(req, &svcResolver)
if err != nil {
Expand All @@ -54,7 +54,7 @@ func (v *ServiceResolverValidator) Handle(ctx context.Context, req admission.Req
v.EnableNSMirroring)
}

func (v *ServiceResolverValidator) List(ctx context.Context) ([]common.ConfigEntryResource, error) {
func (v *ServiceResolverWebhook) List(ctx context.Context) ([]common.ConfigEntryResource, error) {
var svcResolverList ServiceResolverList
if err := v.Client.List(ctx, &svcResolverList); err != nil {
return nil, err
Expand All @@ -66,7 +66,7 @@ func (v *ServiceResolverValidator) List(ctx context.Context) ([]common.ConfigEnt
return entries, nil
}

func (v *ServiceResolverValidator) InjectDecoder(d *admission.Decoder) error {
func (v *ServiceResolverWebhook) InjectDecoder(d *admission.Decoder) error {
v.decoder = d
return nil
}
8 changes: 4 additions & 4 deletions api/v1alpha1/servicerouter_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (

// +kubebuilder:object:generate=false

type ServiceRouterValidator struct {
type ServiceRouterWebhook struct {
ConsulClient *capi.Client
Logger logr.Logger

Expand All @@ -38,7 +38,7 @@ type ServiceRouterValidator struct {
//
// +kubebuilder:webhook:verbs=create;update,path=/mutate-v1alpha1-servicerouter,mutating=true,failurePolicy=fail,groups=consul.hashicorp.com,resources=servicerouters,versions=v1alpha1,name=mutate-servicerouter.consul.hashicorp.com,webhookVersions=v1beta1,sideEffects=None

func (v *ServiceRouterValidator) Handle(ctx context.Context, req admission.Request) admission.Response {
func (v *ServiceRouterWebhook) Handle(ctx context.Context, req admission.Request) admission.Response {
var svcRouter ServiceRouter
err := v.decoder.Decode(req, &svcRouter)
if err != nil {
Expand All @@ -54,7 +54,7 @@ func (v *ServiceRouterValidator) Handle(ctx context.Context, req admission.Reque
v.EnableNSMirroring)
}

func (v *ServiceRouterValidator) List(ctx context.Context) ([]common.ConfigEntryResource, error) {
func (v *ServiceRouterWebhook) List(ctx context.Context) ([]common.ConfigEntryResource, error) {
var svcRouterList ServiceRouterList
if err := v.Client.List(ctx, &svcRouterList); err != nil {
return nil, err
Expand All @@ -66,7 +66,7 @@ func (v *ServiceRouterValidator) List(ctx context.Context) ([]common.ConfigEntry
return entries, nil
}

func (v *ServiceRouterValidator) InjectDecoder(d *admission.Decoder) error {
func (v *ServiceRouterWebhook) InjectDecoder(d *admission.Decoder) error {
v.decoder = d
return nil
}
8 changes: 4 additions & 4 deletions api/v1alpha1/servicesplitter_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (

// +kubebuilder:object:generate=false

type ServiceSplitterValidator struct {
type ServiceSplitterWebhook struct {
ConsulClient *capi.Client
Logger logr.Logger

Expand All @@ -39,7 +39,7 @@ type ServiceSplitterValidator struct {
//
// +kubebuilder:webhook:verbs=create;update,path=/mutate-v1alpha1-servicesplitter,mutating=true,failurePolicy=fail,groups=consul.hashicorp.com,resources=servicesplitters,versions=v1alpha1,name=mutate-servicesplitter.consul.hashicorp.com,webhookVersions=v1beta1,sideEffects=None

func (v *ServiceSplitterValidator) Handle(ctx context.Context, req admission.Request) admission.Response {
func (v *ServiceSplitterWebhook) Handle(ctx context.Context, req admission.Request) admission.Response {
var serviceSplitter ServiceSplitter
err := v.decoder.Decode(req, &serviceSplitter)
if err != nil {
Expand All @@ -55,7 +55,7 @@ func (v *ServiceSplitterValidator) Handle(ctx context.Context, req admission.Req
v.EnableNSMirroring)
}

func (v *ServiceSplitterValidator) List(ctx context.Context) ([]common.ConfigEntryResource, error) {
func (v *ServiceSplitterWebhook) List(ctx context.Context) ([]common.ConfigEntryResource, error) {
var serviceSplitterList ServiceSplitterList
if err := v.Client.List(ctx, &serviceSplitterList); err != nil {
return nil, err
Expand All @@ -67,7 +67,7 @@ func (v *ServiceSplitterValidator) List(ctx context.Context) ([]common.ConfigEnt
return entries, nil
}

func (v *ServiceSplitterValidator) InjectDecoder(d *admission.Decoder) error {
func (v *ServiceSplitterWebhook) InjectDecoder(d *admission.Decoder) error {
v.decoder = d
return nil
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package controllers
package controller

import (
"context"
Expand Down
Loading