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

add unitesting for clientset #15

Closed
wants to merge 2 commits into from
Closed
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
75 changes: 36 additions & 39 deletions api/clientset/v1alpha1/srlinux.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,26 +25,13 @@ var ErrUpdateFailed = errors.New("operation update failed")

// SrlinuxInterface provides access to the Srlinux CRD.
type SrlinuxInterface interface {
List(ctx context.Context, opts *metav1.ListOptions) (*typesv1alpha1.SrlinuxList, error)
Get(
ctx context.Context,
name string,
options *metav1.GetOptions,
) (*typesv1alpha1.Srlinux, error)
List(ctx context.Context, opts metav1.ListOptions) (*typesv1alpha1.SrlinuxList, error)
Get(ctx context.Context, name string, opts metav1.GetOptions) (*typesv1alpha1.Srlinux, error)
Create(ctx context.Context, srlinux *typesv1alpha1.Srlinux) (*typesv1alpha1.Srlinux, error)
Delete(ctx context.Context, name string, opts *metav1.DeleteOptions) error
Watch(ctx context.Context, opts *metav1.ListOptions) (watch.Interface, error)
Unstructured(
ctx context.Context,
name string,
opts *metav1.GetOptions,
subresources ...string,
) (*unstructured.Unstructured, error)
Update(
ctx context.Context,
obj *unstructured.Unstructured,
opts *metav1.UpdateOptions,
) (*typesv1alpha1.Srlinux, error)
Delete(ctx context.Context, name string, opts metav1.DeleteOptions) error
Watch(ctx context.Context, opts metav1.ListOptions) (watch.Interface, error)
Unstructured(ctx context.Context, name string, opts metav1.GetOptions, subresources ...string) (*unstructured.Unstructured, error)
Update(ctx context.Context, obj *unstructured.Unstructured, opts metav1.UpdateOptions) (*typesv1alpha1.Srlinux, error)
}

// Interface is the clientset interface for srlinux.
Expand All @@ -59,11 +46,26 @@ type Clientset struct {
}

var gvr = schema.GroupVersionResource{ // nolint: gochecknoglobals
Group: typesv1alpha1.GroupVersion.Group,
Version: typesv1alpha1.GroupVersion.Version,
Group: typesv1alpha1.GroupName,
Version: typesv1alpha1.GroupVersion,
Resource: "srlinuxes",
}

func GVR() schema.GroupVersionResource {
return gvr
}

var (
groupVersion = &schema.GroupVersion{
Group: typesv1alpha1.GroupName,
Version: typesv1alpha1.GroupVersion,
}
)

func GV() *schema.GroupVersion {
return groupVersion
}

// NewForConfig returns a new Clientset based on c.
func NewForConfig(c *rest.Config) (*Clientset, error) {
config := *c
Expand Down Expand Up @@ -108,14 +110,14 @@ type srlinuxClient struct {
// List gets a list of SRLinux resources.
func (s *srlinuxClient) List(
ctx context.Context,
opts *metav1.ListOptions,
opts metav1.ListOptions,
) (*typesv1alpha1.SrlinuxList, error) {
result := typesv1alpha1.SrlinuxList{}
err := s.restClient.
Get().
Namespace(s.ns).
Resource(gvr.Resource).
VersionedParams(opts, scheme.ParameterCodec).
VersionedParams(&opts, scheme.ParameterCodec).
Do(ctx).
Into(&result)

Expand All @@ -126,15 +128,15 @@ func (s *srlinuxClient) List(
func (s *srlinuxClient) Get(
ctx context.Context,
name string,
opts *metav1.GetOptions,
opts metav1.GetOptions,
) (*typesv1alpha1.Srlinux, error) {
result := typesv1alpha1.Srlinux{}
err := s.restClient.
Get().
Namespace(s.ns).
Resource(gvr.Resource).
Name(name).
VersionedParams(opts, scheme.ParameterCodec).
VersionedParams(&opts, scheme.ParameterCodec).
Do(ctx).
Into(&result)

Expand All @@ -160,24 +162,24 @@ func (s *srlinuxClient) Create(

func (s *srlinuxClient) Watch(
ctx context.Context,
opts *metav1.ListOptions,
opts metav1.ListOptions,
) (watch.Interface, error) {
opts.Watch = true

return s.restClient.
Get().
Namespace(s.ns).
Resource(gvr.Resource).
VersionedParams(opts, scheme.ParameterCodec).
VersionedParams(&opts, scheme.ParameterCodec).
Watch(ctx)
}

func (s *srlinuxClient) Delete(ctx context.Context, name string, opts *metav1.DeleteOptions) error {
func (s *srlinuxClient) Delete(ctx context.Context, name string, opts metav1.DeleteOptions) error {
return s.restClient.
Delete().
Namespace(s.ns).
Resource(gvr.Resource).
VersionedParams(opts, scheme.ParameterCodec).
VersionedParams(&opts, scheme.ParameterCodec).
Name(name).
Do(ctx).
Error()
Expand All @@ -186,11 +188,11 @@ func (s *srlinuxClient) Delete(ctx context.Context, name string, opts *metav1.De
func (s *srlinuxClient) Update(
ctx context.Context,
obj *unstructured.Unstructured,
_ *metav1.UpdateOptions,
opts metav1.UpdateOptions,
) (*typesv1alpha1.Srlinux, error) {
result := typesv1alpha1.Srlinux{}

obj, err := s.dInterface.Namespace(s.ns).UpdateStatus(ctx, obj, metav1.UpdateOptions{})
obj, err := s.dInterface.Namespace(s.ns).UpdateStatus(ctx, obj, opts)
if err != nil {
return nil, err
}
Expand All @@ -203,15 +205,10 @@ func (s *srlinuxClient) Update(
return &result, nil
}

func (s *srlinuxClient) Unstructured(
ctx context.Context,
name string,
opts *metav1.GetOptions,
subresources ...string,
) (*unstructured.Unstructured, error) {
return s.dInterface.Namespace(s.ns).Get(ctx, name, *opts, subresources...)
func (s *srlinuxClient) Unstructured(ctx context.Context, name string, opts metav1.GetOptions, subresources ...string) (*unstructured.Unstructured, error) {
return s.dInterface.Namespace(s.ns).Get(ctx, name, opts, subresources...)
}

func init() {
_ = typesv1alpha1.AddToScheme(scheme.Scheme)
typesv1alpha1.AddToScheme(scheme.Scheme)
}
Loading