Skip to content

Commit

Permalink
Add assertions for types implementing interfaces
Browse files Browse the repository at this point in the history
  • Loading branch information
feloy committed Jul 1, 2022
1 parent 2217725 commit 3187b1c
Show file tree
Hide file tree
Showing 75 changed files with 178 additions and 5 deletions.
2 changes: 2 additions & 0 deletions pkg/alizer/alizer.go
Expand Up @@ -10,6 +10,8 @@ type Alizer struct {
registryClient registry.Client
}

var _ Client = (*Alizer)(nil)

func NewAlizerClient(registryClient registry.Client) *Alizer {
return &Alizer{
registryClient: registryClient,
Expand Down
2 changes: 2 additions & 0 deletions pkg/auth/login.go
Expand Up @@ -15,6 +15,8 @@ import (

type KubernetesClient struct{}

var _ Client = (*KubernetesClient)(nil)

func NewKubernetesClient() *KubernetesClient {
return &KubernetesClient{}
}
Expand Down
2 changes: 2 additions & 0 deletions pkg/binding/asker/survey_asker.go
Expand Up @@ -13,6 +13,8 @@ const (

type Survey struct{}

var _ Asker = (*Survey)(nil)

func NewSurveyAsker() *Survey {
return &Survey{}
}
Expand Down
2 changes: 2 additions & 0 deletions pkg/binding/backend/flags.go
Expand Up @@ -23,6 +23,8 @@ const (
// FlagsBackend is a backend that will extract all needed information from flags passed to the command
type FlagsBackend struct{}

var _ AddBindingBackend = (*FlagsBackend)(nil)

func NewFlagsBackend() *FlagsBackend {
return &FlagsBackend{}
}
Expand Down
2 changes: 2 additions & 0 deletions pkg/binding/backend/interactive.go
Expand Up @@ -22,6 +22,8 @@ type InteractiveBackend struct {
kubernetesClient kclient.ClientInterface
}

var _ AddBindingBackend = (*InteractiveBackend)(nil)

func NewInteractiveBackend(askerClient asker.Asker, kubernetesClient kclient.ClientInterface) *InteractiveBackend {
return &InteractiveBackend{
askerClient: askerClient,
Expand Down
2 changes: 2 additions & 0 deletions pkg/binding/binding.go
Expand Up @@ -34,6 +34,8 @@ type BindingClient struct {
kubernetesClient kclient.ClientInterface
}

var _ Client = (*BindingClient)(nil)

func NewBindingClient(kubernetesClient kclient.ClientInterface) *BindingClient {
// We create the asker client and the backends here and not at the CLI level, as we want to hide these details to the CLI
askerClient := asker.NewSurveyAsker()
Expand Down
2 changes: 2 additions & 0 deletions pkg/component/delete/delete.go
Expand Up @@ -24,6 +24,8 @@ type DeleteComponentClient struct {
kubeClient kclient.ClientInterface
}

var _ Client = (*DeleteComponentClient)(nil)

func NewDeleteComponentClient(kubeClient kclient.ClientInterface) *DeleteComponentClient {
return &DeleteComponentClient{
kubeClient: kubeClient,
Expand Down
3 changes: 3 additions & 0 deletions pkg/component/exec_handler.go
Expand Up @@ -7,6 +7,7 @@ import (
"github.com/devfile/api/v2/pkg/apis/workspaces/v1alpha2"

"github.com/redhat-developer/odo/pkg/kclient"
"github.com/redhat-developer/odo/pkg/libdevfile"
"github.com/redhat-developer/odo/pkg/log"
"github.com/redhat-developer/odo/pkg/machineoutput"
"github.com/redhat-developer/odo/pkg/remotecmd"
Expand All @@ -22,6 +23,8 @@ type execHandler struct {
show bool
}

var _ libdevfile.Handler = (*execHandler)(nil)

const ShellExecutable string = "/bin/sh"

func NewExecHandler(kubeClient kclient.ClientInterface, appName, cmpName, podName, msg string, show bool) *execHandler {
Expand Down
5 changes: 5 additions & 0 deletions pkg/component/pushed_component.go
Expand Up @@ -44,6 +44,9 @@ type defaultPushedComponent struct {
storageClient storage.Client
}

var _ provider = (*defaultPushedComponent)(nil)
var _ PushedComponent = (*defaultPushedComponent)(nil)

func (d defaultPushedComponent) GetLabels() map[string]string {
return d.provider.GetLabels()
}
Expand Down Expand Up @@ -90,6 +93,8 @@ type devfileComponent struct {
d v1.Deployment
}

var _ provider = (*devfileComponent)(nil)

func (d devfileComponent) GetLinkedSecrets() (secretMounts []SecretMount) {
for _, container := range d.d.Spec.Template.Spec.Containers {
for _, env := range container.EnvFrom {
Expand Down
4 changes: 4 additions & 0 deletions pkg/deploy/deploy.go
Expand Up @@ -23,6 +23,8 @@ type DeployClient struct {
kubeClient kclient.ClientInterface
}

var _ Client = (*DeployClient)(nil)

func NewDeployClient(kubeClient kclient.ClientInterface) *DeployClient {
return &DeployClient{
kubeClient: kubeClient,
Expand All @@ -41,6 +43,8 @@ type deployHandler struct {
appName string
}

var _ libdevfile.Handler = (*deployHandler)(nil)

func newDeployHandler(devfileObj parser.DevfileObj, path string, kubeClient kclient.ClientInterface, appName string) *deployHandler {
return &deployHandler{
devfileObj: devfileObj,
Expand Down
5 changes: 2 additions & 3 deletions pkg/dev/dev.go
Expand Up @@ -15,13 +15,12 @@ import (
"github.com/redhat-developer/odo/pkg/watch"
)

// this causes compilation to fail if DevClient struct doesn't implement Client interface
var _ Client = (*DevClient)(nil)

type DevClient struct {
watchClient watch.Client
}

var _ Client = (*DevClient)(nil)

func NewDevClient(watchClient watch.Client) *DevClient {
return &DevClient{
watchClient: watchClient,
Expand Down
2 changes: 2 additions & 0 deletions pkg/devfile/adapters/kubernetes/adapter.go
Expand Up @@ -15,6 +15,8 @@ type Adapter struct {
componentAdapter common.ComponentAdapter
}

var _ common.ComponentAdapter = (*Adapter)(nil)

type KubernetesContext struct {
Namespace string
}
Expand Down
3 changes: 3 additions & 0 deletions pkg/devfile/adapters/kubernetes/component/adapter.go
Expand Up @@ -89,6 +89,9 @@ type Adapter struct {
deployment *appsv1.Deployment
}

var _ sync.SyncClient = (*Adapter)(nil)
var _ common.ComponentAdapter = (*Adapter)(nil)

// Push updates the component if a matching component exists or creates one if it doesn't exist
// Once the component has started, it will sync the source code to it.
func (a Adapter) Push(parameters common.PushParameters) (err error) {
Expand Down
3 changes: 3 additions & 0 deletions pkg/devfile/adapters/kubernetes/component/commandhandler.go
Expand Up @@ -13,6 +13,7 @@ import (
"github.com/redhat-developer/odo/pkg/libdevfile"
"github.com/redhat-developer/odo/pkg/log"
"github.com/redhat-developer/odo/pkg/remotecmd"
"github.com/redhat-developer/odo/pkg/sync"
"github.com/redhat-developer/odo/pkg/task"
"github.com/redhat-developer/odo/pkg/util"
)
Expand All @@ -26,6 +27,8 @@ type adapterHandler struct {
}

var _ libdevfile.Handler = (*adapterHandler)(nil)
var _ common.ComponentAdapter = (*adapterHandler)(nil)
var _ sync.SyncClient = (*adapterHandler)(nil)

func (a *adapterHandler) ApplyImage(_ devfilev1.Component) error {
klog.V(2).Info("this handler can only handle exec commands in container components, not image components")
Expand Down
2 changes: 2 additions & 0 deletions pkg/devfile/image/docker_compatible.go
Expand Up @@ -19,6 +19,8 @@ type DockerCompatibleBackend struct {
name string
}

var _ Backend = (*DockerCompatibleBackend)(nil)

func NewDockerCompatibleBackend(name string) *DockerCompatibleBackend {
return &DockerCompatibleBackend{name: name}
}
Expand Down
2 changes: 2 additions & 0 deletions pkg/envinfo/envinfo.go
Expand Up @@ -61,6 +61,8 @@ type EnvSpecificInfo struct {
envinfoFileExists bool
}

var _ localConfigProvider.LocalConfigProvider = (*EnvSpecificInfo)(nil)

func (esi EnvSpecificInfo) GetDevfilePath() string {
return esi.devfilePath
}
Expand Down
2 changes: 2 additions & 0 deletions pkg/init/asker/asker.go
Expand Up @@ -12,6 +12,8 @@ import (

type Survey struct{}

var _ Asker = (*Survey)(nil)

func NewSurveyAsker() *Survey {
return &Survey{}
}
Expand Down
2 changes: 2 additions & 0 deletions pkg/init/backend/alizer.go
Expand Up @@ -16,6 +16,8 @@ type AlizerBackend struct {
alizerClient alizer.Client
}

var _ InitBackend = (*AlizerBackend)(nil)

func NewAlizerBackend(askerClient asker.Asker, alizerClient alizer.Client) *AlizerBackend {
return &AlizerBackend{
askerClient: askerClient,
Expand Down
2 changes: 2 additions & 0 deletions pkg/init/backend/flags.go
Expand Up @@ -30,6 +30,8 @@ type FlagsBackend struct {
preferenceClient preference.Client
}

var _ InitBackend = (*FlagsBackend)(nil)

func NewFlagsBackend(preferenceClient preference.Client) *FlagsBackend {
return &FlagsBackend{
preferenceClient: preferenceClient,
Expand Down
2 changes: 2 additions & 0 deletions pkg/init/backend/interactive.go
Expand Up @@ -29,6 +29,8 @@ type InteractiveBackend struct {
registryClient registry.Client
}

var _ InitBackend = (*InteractiveBackend)(nil)

func NewInteractiveBackend(askerClient asker.Asker, registryClient registry.Client) *InteractiveBackend {
return &InteractiveBackend{
askerClient: askerClient,
Expand Down
2 changes: 2 additions & 0 deletions pkg/init/init.go
Expand Up @@ -37,6 +37,8 @@ type InitClient struct {
registryClient registry.Client
}

var _ Client = (*InitClient)(nil)

func NewInitClient(fsys filesystem.Filesystem, preferenceClient preference.Client, registryClient registry.Client, alizerClient alizer.Client) *InitClient {
// We create the asker client and the backends here and not at the CLI level, as we want to hide these details to the CLI
askerClient := asker.NewSurveyAsker()
Expand Down
2 changes: 2 additions & 0 deletions pkg/kclient/kclient.go
Expand Up @@ -71,6 +71,8 @@ type Client struct {
routeClient routeclientset.RouteV1Interface
}

var _ ClientInterface = (*Client)(nil)

// New creates a new client
func New() (*Client, error) {
return NewForConfig(nil)
Expand Down
2 changes: 2 additions & 0 deletions pkg/libdevfile/command_apply.go
Expand Up @@ -12,6 +12,8 @@ type applyCommand struct {
devfileObj parser.DevfileObj
}

var _ command = (*applyCommand)(nil)

// newApplyCommand creates a new applyCommand instance
func newApplyCommand(devfileObj parser.DevfileObj, command v1alpha2.Command) *applyCommand {
return &applyCommand{
Expand Down
2 changes: 2 additions & 0 deletions pkg/libdevfile/command_composite.go
Expand Up @@ -14,6 +14,8 @@ type compositeCommand struct {
devfileObj parser.DevfileObj
}

var _ command = (*compositeCommand)(nil)

// newCompositeCommand creates a new command implementation which will execute the provided commands in the specified order
func newCompositeCommand(devfileObj parser.DevfileObj, command v1alpha2.Command) *compositeCommand {
return &compositeCommand{
Expand Down
2 changes: 2 additions & 0 deletions pkg/libdevfile/command_composite_parallel.go
Expand Up @@ -15,6 +15,8 @@ type parallelCompositeCommand struct {
devfileObj parser.DevfileObj
}

var _ command = (*parallelCompositeCommand)(nil)

// newParallelCompositeCommand creates a new command implementation which will execute the provided commands in parallel
func newParallelCompositeCommand(devfileObj parser.DevfileObj, command v1alpha2.Command) *parallelCompositeCommand {
return &parallelCompositeCommand{
Expand Down
2 changes: 2 additions & 0 deletions pkg/libdevfile/command_exec.go
Expand Up @@ -11,6 +11,8 @@ type execCommand struct {
devfileObj parser.DevfileObj
}

var _ command = (*execCommand)(nil)

// newExecCommand creates a new execCommand instance, adapting the devfile-defined command to run in the target component's
// container, modifying it to add environment variables or adapting the path as needed.
func newExecCommand(devfileObj parser.DevfileObj, command v1alpha2.Command) *execCommand {
Expand Down
2 changes: 2 additions & 0 deletions pkg/libdevfile/component_container.go
Expand Up @@ -11,6 +11,8 @@ type containerComponent struct {
devfileObj parser.DevfileObj
}

var _ component = (*containerComponent)(nil)

func newContainerComponent(devfileObj parser.DevfileObj, component v1alpha2.Component) *containerComponent {
return &containerComponent{
component: component,
Expand Down
2 changes: 2 additions & 0 deletions pkg/libdevfile/component_image.go
Expand Up @@ -11,6 +11,8 @@ type imageComponent struct {
devfileObj parser.DevfileObj
}

var _ component = (*imageComponent)(nil)

func newImageComponent(devfileObj parser.DevfileObj, component v1alpha2.Component) *imageComponent {
return &imageComponent{
component: component,
Expand Down
2 changes: 2 additions & 0 deletions pkg/libdevfile/component_kubernetes.go
Expand Up @@ -11,6 +11,8 @@ type kubernetesComponent struct {
devfileObj parser.DevfileObj
}

var _ component = (*kubernetesComponent)(nil)

func newKubernetesComponent(devfileObj parser.DevfileObj, component v1alpha2.Component) *kubernetesComponent {
return &kubernetesComponent{
component: component,
Expand Down
2 changes: 2 additions & 0 deletions pkg/libdevfile/component_openshift.go
Expand Up @@ -11,6 +11,8 @@ type openshiftComponent struct {
devfileObj parser.DevfileObj
}

var _ component = (*openshiftComponent)(nil)

func newOpenshiftComponent(devfileObj parser.DevfileObj, component v1alpha2.Component) *openshiftComponent {
return &openshiftComponent{
component: component,
Expand Down
2 changes: 2 additions & 0 deletions pkg/libdevfile/component_volume.go
Expand Up @@ -11,6 +11,8 @@ type volumeComponent struct {
devfileObj parser.DevfileObj
}

var _ component = (*volumeComponent)(nil)

func newVolumeComponent(devfileObj parser.DevfileObj, component v1alpha2.Component) *volumeComponent {
return &volumeComponent{
component: component,
Expand Down
2 changes: 2 additions & 0 deletions pkg/logs/logs.go
Expand Up @@ -19,6 +19,8 @@ type LogsClient struct {
kubernetesClient kclient.ClientInterface
}

var _ Client = (*LogsClient)(nil)

func NewLogsClient(kubernetesClient kclient.ClientInterface) *LogsClient {
return &LogsClient{
kubernetesClient: kubernetesClient,
Expand Down
4 changes: 4 additions & 0 deletions pkg/machineoutput/types_event_logging.go
Expand Up @@ -134,9 +134,13 @@ type MachineEventLogEntry interface {
type NoOpMachineEventLoggingClient struct {
}

var _ MachineEventLoggingClient = (*NoOpMachineEventLoggingClient)(nil)

// ConsoleMachineEventLoggingClient will output all events to the console as JSON
type ConsoleMachineEventLoggingClient struct {

// logFunc is an optional function that can be used instead of writing via the standard machine out logic
logFunc func(machineOutput MachineEventWrapper)
}

var _ MachineEventLoggingClient = (*ConsoleMachineEventLoggingClient)(nil)
2 changes: 2 additions & 0 deletions pkg/odo/cli/add/binding/binding.go
Expand Up @@ -53,6 +53,8 @@ type AddBindingOptions struct {
clientset *clientset.Clientset
}

var _ genericclioptions.Runnable = (*AddBindingOptions)(nil)

// NewAddBindingOptions returns new instance of ComponentOptions
func NewAddBindingOptions() *AddBindingOptions {
return &AddBindingOptions{}
Expand Down
3 changes: 3 additions & 0 deletions pkg/odo/cli/alizer/alizer.go
Expand Up @@ -22,6 +22,9 @@ type AlizerOptions struct {
clientset *clientset.Clientset
}

var _ genericclioptions.Runnable = (*AlizerOptions)(nil)
var _ genericclioptions.JsonOutputter = (*AlizerOptions)(nil)

// NewAlizerOptions creates a new AlizerOptions instance
func NewAlizerOptions() *AlizerOptions {
return &AlizerOptions{}
Expand Down
2 changes: 2 additions & 0 deletions pkg/odo/cli/build_images/build_images.go
Expand Up @@ -28,6 +28,8 @@ type BuildImagesOptions struct {
contextFlag string
}

var _ genericclioptions.Runnable = (*BuildImagesOptions)(nil)

var buildImagesExample = templates.Examples(`
# Build images defined in the devfile
%[1]s
Expand Down
2 changes: 2 additions & 0 deletions pkg/odo/cli/create/namespace/namespace.go
Expand Up @@ -53,6 +53,8 @@ type NamespaceCreateOptions struct {
commandName string
}

var _ genericclioptions.Runnable = (*NamespaceCreateOptions)(nil)

// NewNamespaceCreateOptions creates a NamespaceCreateOptions instance
func NewNamespaceCreateOptions() *NamespaceCreateOptions {
return &NamespaceCreateOptions{}
Expand Down
2 changes: 2 additions & 0 deletions pkg/odo/cli/delete/component/component.go
Expand Up @@ -52,6 +52,8 @@ type ComponentOptions struct {
clientset *clientset.Clientset
}

var _ genericclioptions.Runnable = (*ComponentOptions)(nil)

// NewComponentOptions returns new instance of ComponentOptions
func NewComponentOptions() *ComponentOptions {
return &ComponentOptions{}
Expand Down

0 comments on commit 3187b1c

Please sign in to comment.