Skip to content
This repository has been archived by the owner on Nov 3, 2024. It is now read-only.

Commit

Permalink
Add NewRequestWithContext, InvokeWithContext and InvokeFuncWithContext
Browse files Browse the repository at this point in the history
Signed-off-by: tylerslaton <[email protected]>
  • Loading branch information
tylerslaton committed Oct 23, 2023
1 parent af2b683 commit 1dcdb08
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions pkg/router/tester/tester.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,17 @@ func (b *Harness) InvokeFunc(t *testing.T, input kclient.Object, handler router.
return b.Invoke(t, input, handler)
}

func (b *Harness) InvokeFuncWithContext(t *testing.T, ctx context.Context, input kclient.Object, handler router.HandlerFunc) (*Response, error) {
t.Helper()
return b.InvokeWithContext(t, ctx, input, handler)
}

func NewRequest(t *testing.T, scheme *runtime.Scheme, input kclient.Object, existing ...kclient.Object) router.Request {
t.Helper()
return NewRequestWithContext(t, context.TODO(), scheme, input, existing...)
}

func NewRequestWithContext(t *testing.T, ctx context.Context, scheme *runtime.Scheme, input kclient.Object, existing ...kclient.Object) router.Request {
t.Helper()
gvk, err := apiutil.GVKForObject(input, scheme)
if err != nil {
Expand All @@ -164,7 +174,7 @@ func NewRequest(t *testing.T, scheme *runtime.Scheme, input kclient.Object, exis
SchemeObj: scheme,
},
Object: input,
Ctx: context.TODO(),
Ctx: ctx,
GVK: gvk,
Namespace: input.GetNamespace(),
Name: input.GetName(),
Expand All @@ -174,9 +184,14 @@ func NewRequest(t *testing.T, scheme *runtime.Scheme, input kclient.Object, exis
}

func (b *Harness) Invoke(t *testing.T, input kclient.Object, handler router.Handler) (*Response, error) {
t.Helper()
return b.InvokeWithContext(t, context.TODO(), input, handler)
}

func (b *Harness) InvokeWithContext(t *testing.T, ctx context.Context, input kclient.Object, handler router.Handler) (*Response, error) {
t.Helper()
var (
req = NewRequest(t, b.Scheme, input, b.Existing...)
req = NewRequestWithContext(t, ctx, b.Scheme, input, b.Existing...)
resp = Response{
Client: req.Client.(*Client),
}
Expand Down

0 comments on commit 1dcdb08

Please sign in to comment.