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

feat: add context to remove call #17

Merged
merged 3 commits into from
Jan 15, 2024
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
4 changes: 2 additions & 2 deletions pkg/nuke/nuke.go
Original file line number Diff line number Diff line change
Expand Up @@ -464,9 +464,9 @@ func (n *Nuke) HandleQueue(ctx context.Context) {

// HandleRemove is used to handle the removal of a resource. It will remove the resource and set the state of the
// resource to pending if it was successful or failed if it was not.
func (n *Nuke) HandleRemove(_ context.Context, item *queue.Item) {
func (n *Nuke) HandleRemove(ctx context.Context, item *queue.Item) {
// TODO: pass context to remove for remove functions to use
err := item.Resource.Remove()
err := item.Resource.Remove(ctx)
if err != nil {
var resErr liberrors.ErrHoldResource
if errors.As(err, &resErr) {
Expand Down
2 changes: 1 addition & 1 deletion pkg/nuke/nuke_filter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ func (r TestResourceFilter) Properties() types.Properties {
return props
}

func (r TestResourceFilter) Remove() error {
func (r TestResourceFilter) Remove(_ context.Context) error {
return nil
}

Expand Down
8 changes: 5 additions & 3 deletions pkg/nuke/nuke_run_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ import (

type TestResourceSuccess struct{}

func (r *TestResourceSuccess) Remove() error { return nil }
func (r *TestResourceSuccess) String() string { return "TestResourceFailure" }
func (r *TestResourceSuccess) Remove(_ context.Context) error { return nil }
func (r *TestResourceSuccess) String() string { return "TestResourceFailure" }

type TestResourceSuccessLister struct {
listed bool
Expand All @@ -32,7 +32,9 @@ func (l *TestResourceSuccessLister) List(_ context.Context, o interface{}) ([]re

type TestResourceFailure struct{}

func (r *TestResourceFailure) Remove() error { return fmt.Errorf("unable to remove") }
func (r *TestResourceFailure) Remove(_ context.Context) error {
return fmt.Errorf("unable to remove")
}
func (r *TestResourceFailure) String() string { return "TestResourceFailure" }

type TestResourceFailureLister struct{}
Expand Down
4 changes: 2 additions & 2 deletions pkg/nuke/nuke_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ type TestResource3 struct {
Error bool
}

func (r TestResource3) Remove() error {
func (r TestResource3) Remove(_ context.Context) error {
if r.Error {
return fmt.Errorf("remove error")
}
Expand Down Expand Up @@ -344,7 +344,7 @@ type TestResource4 struct {
parentID string
}

func (r *TestResource4) Remove() error {
func (r *TestResource4) Remove(_ context.Context) error {
if r.parentID != "" {
parentFound := false

Expand Down
4 changes: 2 additions & 2 deletions pkg/nuke/scan_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func (r TestResource) Filter() error {
return nil
}

func (r TestResource) Remove() error {
func (r TestResource) Remove(_ context.Context) error {
if r.RemoveError {
return fmt.Errorf("remove error")
}
Expand All @@ -81,7 +81,7 @@ func (r TestResource2) Filter() error {
return nil
}

func (r TestResource2) Remove() error {
func (r TestResource2) Remove(_ context.Context) error {
if r.RemoveError {
return fmt.Errorf("remove error")
}
Expand Down
10 changes: 5 additions & 5 deletions pkg/queue/item_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ func (r *TestItemResource) Properties() types.Properties {
props.Set(r.id, "testing")
return props
}
func (r *TestItemResource) Remove() error {
func (r *TestItemResource) Remove(_ context.Context) error {
return nil
}
func (r *TestItemResource) String() string {
Expand All @@ -28,7 +28,7 @@ func (r *TestItemResource) String() string {

type TestItemResource2 struct{}

func (r TestItemResource2) Remove() error {
func (r TestItemResource2) Remove(_ context.Context) error {
return nil
}

Expand Down Expand Up @@ -169,7 +169,7 @@ func Test_ItemPrint(t *testing.T) {

type TestItemResourceProperties struct{}

func (r *TestItemResourceProperties) Remove() error {
func (r *TestItemResourceProperties) Remove(_ context.Context) error {
return nil
}
func (r *TestItemResourceProperties) Properties() types.Properties {
Expand All @@ -191,7 +191,7 @@ func Test_ItemEqualProperties(t *testing.T) {

type TestItemResourceStringer struct{}

func (r *TestItemResourceStringer) Remove() error {
func (r *TestItemResourceStringer) Remove(_ context.Context) error {
return nil
}
func (r *TestItemResourceStringer) String() string {
Expand Down Expand Up @@ -221,7 +221,7 @@ func Test_ItemEqualStringer(t *testing.T) {

type TestItemResourceNothing struct{}

func (r *TestItemResourceNothing) Remove() error {
func (r *TestItemResourceNothing) Remove(_ context.Context) error {
return nil
}

Expand Down
4 changes: 3 additions & 1 deletion pkg/resource/resource.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
package resource

import (
"context"

"github.com/ekristen/libnuke/pkg/featureflag"
"github.com/ekristen/libnuke/pkg/types"
)

type Resource interface {
Remove() error
Remove(ctx context.Context) error
}

type Filter interface {
Expand Down
5 changes: 3 additions & 2 deletions pkg/resource/resource_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package resource

import (
"context"
"fmt"
"testing"

Expand All @@ -15,7 +16,7 @@ type TestResource struct {
Flags *featureflag.FeatureFlags
}

func (r *TestResource) Remove() error {
func (r *TestResource) Remove(_ context.Context) error {
return fmt.Errorf("remove called")
}

Expand All @@ -39,7 +40,7 @@ func (r *TestResource) FeatureFlags(ff *featureflag.FeatureFlags) {

func TestInterfaceResource(t *testing.T) {
r := TestResource{}
err := r.Remove()
err := r.Remove(context.TODO())
assert.Error(t, err)
assert.Equal(t, "remove called", err.Error())
}
Expand Down
Loading