test: use cancelation from ktesting
The return type of ktesting.NewTestContext is now a TContext. Code which combined it WithCancel often didn't compile anymore (cannot overwrite ktesting.TContext with context.Context). This is a good thing because all of that code can be simplified to let ktesting handle the cancelation.
This commit is contained in:
@@ -17,7 +17,6 @@ limitations under the License.
|
||||
package apiserver
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"strings"
|
||||
"testing"
|
||||
@@ -33,11 +32,9 @@ import (
|
||||
|
||||
// Tests that the apiserver limits the number of operations in a json patch.
|
||||
func TestMaxJSONPatchOperations(t *testing.T) {
|
||||
_, ctx := ktesting.NewTestContext(t)
|
||||
ctx, cancel := context.WithCancel(ctx)
|
||||
defer cancel()
|
||||
tCtx := ktesting.Init(t)
|
||||
|
||||
clientSet, _, tearDownFn := framework.StartTestServer(ctx, t, framework.TestServerSetup{
|
||||
clientSet, _, tearDownFn := framework.StartTestServer(tCtx, t, framework.TestServerSetup{
|
||||
ModifyServerRunOptions: func(opts *options.ServerRunOptions) {
|
||||
opts.GenericServerRunOptions.MaxRequestBodyBytes = 1024 * 1024
|
||||
},
|
||||
@@ -55,13 +52,13 @@ func TestMaxJSONPatchOperations(t *testing.T) {
|
||||
Name: "test",
|
||||
},
|
||||
}
|
||||
_, err := clientSet.CoreV1().Secrets("default").Create(ctx, secret, metav1.CreateOptions{})
|
||||
_, err := clientSet.CoreV1().Secrets("default").Create(tCtx, secret, metav1.CreateOptions{})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
err = c.Patch(types.JSONPatchType).AbsPath(fmt.Sprintf("/api/v1/namespaces/default/secrets/test")).
|
||||
Body(hugePatch).Do(ctx).Error()
|
||||
Body(hugePatch).Do(tCtx).Error()
|
||||
if err == nil {
|
||||
t.Fatalf("unexpected no error")
|
||||
}
|
||||
|
Reference in New Issue
Block a user