@@ -18,7 +18,6 @@ package apiserver
18
18
19
19
import (
20
20
"context"
21
- "fmt"
22
21
"strings"
23
22
"testing"
24
23
@@ -41,7 +40,7 @@ func TestMaxResourceSize(t *testing.T) {
41
40
42
41
c := clientSet .CoreV1 ().RESTClient ()
43
42
t .Run ("Create should limit the request body size" , func (t * testing.T ) {
44
- err := c .Post ().AbsPath (fmt . Sprintf ( "/api/v1/namespaces/default/pods" ) ).
43
+ err := c .Post ().AbsPath ("/api/v1/namespaces/default/pods" ).
45
44
Body (hugeData ).Do (context .TODO ()).Error ()
46
45
if err == nil {
47
46
t .Fatalf ("unexpected no error" )
@@ -64,7 +63,7 @@ func TestMaxResourceSize(t *testing.T) {
64
63
}
65
64
66
65
t .Run ("Update should limit the request body size" , func (t * testing.T ) {
67
- err = c .Put ().AbsPath (fmt . Sprintf ( "/api/v1/namespaces/default/secrets/test" ) ).
66
+ err = c .Put ().AbsPath ("/api/v1/namespaces/default/secrets/test" ).
68
67
Body (hugeData ).Do (context .TODO ()).Error ()
69
68
if err == nil {
70
69
t .Fatalf ("unexpected no error" )
@@ -75,7 +74,7 @@ func TestMaxResourceSize(t *testing.T) {
75
74
}
76
75
})
77
76
t .Run ("Patch should limit the request body size" , func (t * testing.T ) {
78
- err = c .Patch (types .JSONPatchType ).AbsPath (fmt . Sprintf ( "/api/v1/namespaces/default/secrets/test" ) ).
77
+ err = c .Patch (types .JSONPatchType ).AbsPath ("/api/v1/namespaces/default/secrets/test" ).
79
78
Body (hugeData ).Do (context .TODO ()).Error ()
80
79
if err == nil {
81
80
t .Fatalf ("unexpected no error" )
@@ -87,70 +86,70 @@ func TestMaxResourceSize(t *testing.T) {
87
86
})
88
87
t .Run ("JSONPatchType should handle a patch just under the max limit" , func (t * testing.T ) {
89
88
patchBody := []byte (`[{"op":"add","path":"/foo","value":` + strings .Repeat ("[" , 3 * 1024 * 1024 / 2 - 100 ) + strings .Repeat ("]" , 3 * 1024 * 1024 / 2 - 100 ) + `}]` )
90
- err = rest .Patch (types .JSONPatchType ).AbsPath (fmt . Sprintf ( "/api/v1/namespaces/default/secrets/test" ) ).
89
+ err = rest .Patch (types .JSONPatchType ).AbsPath ("/api/v1/namespaces/default/secrets/test" ).
91
90
Body (patchBody ).Do (context .TODO ()).Error ()
92
91
if err != nil && ! apierrors .IsBadRequest (err ) {
93
92
t .Errorf ("expected success or bad request err, got %v" , err )
94
93
}
95
94
})
96
95
t .Run ("JSONPatchType should handle a valid patch just under the max limit" , func (t * testing.T ) {
97
96
patchBody := []byte (`[{"op":"add","path":"/foo","value":0` + strings .Repeat (" " , 3 * 1024 * 1024 - 100 ) + `}]` )
98
- err = rest .Patch (types .JSONPatchType ).AbsPath (fmt . Sprintf ( "/api/v1/namespaces/default/secrets/test" ) ).
97
+ err = rest .Patch (types .JSONPatchType ).AbsPath ("/api/v1/namespaces/default/secrets/test" ).
99
98
Body (patchBody ).Do (context .TODO ()).Error ()
100
99
if err != nil {
101
100
t .Errorf ("unexpected error: %v" , err )
102
101
}
103
102
})
104
103
t .Run ("MergePatchType should handle a patch just under the max limit" , func (t * testing.T ) {
105
104
patchBody := []byte (`{"value":` + strings .Repeat ("[" , 3 * 1024 * 1024 / 2 - 100 ) + strings .Repeat ("]" , 3 * 1024 * 1024 / 2 - 100 ) + `}` )
106
- err = rest .Patch (types .MergePatchType ).AbsPath (fmt . Sprintf ( "/api/v1/namespaces/default/secrets/test" ) ).
105
+ err = rest .Patch (types .MergePatchType ).AbsPath ("/api/v1/namespaces/default/secrets/test" ).
107
106
Body (patchBody ).Do (context .TODO ()).Error ()
108
107
if err != nil && ! apierrors .IsBadRequest (err ) {
109
108
t .Errorf ("expected success or bad request err, got %v" , err )
110
109
}
111
110
})
112
111
t .Run ("MergePatchType should handle a valid patch just under the max limit" , func (t * testing.T ) {
113
112
patchBody := []byte (`{"value":0` + strings .Repeat (" " , 3 * 1024 * 1024 - 100 ) + `}` )
114
- err = rest .Patch (types .MergePatchType ).AbsPath (fmt . Sprintf ( "/api/v1/namespaces/default/secrets/test" ) ).
113
+ err = rest .Patch (types .MergePatchType ).AbsPath ("/api/v1/namespaces/default/secrets/test" ).
115
114
Body (patchBody ).Do (context .TODO ()).Error ()
116
115
if err != nil {
117
116
t .Errorf ("unexpected error: %v" , err )
118
117
}
119
118
})
120
119
t .Run ("StrategicMergePatchType should handle a patch just under the max limit" , func (t * testing.T ) {
121
120
patchBody := []byte (`{"value":` + strings .Repeat ("[" , 3 * 1024 * 1024 / 2 - 100 ) + strings .Repeat ("]" , 3 * 1024 * 1024 / 2 - 100 ) + `}` )
122
- err = rest .Patch (types .StrategicMergePatchType ).AbsPath (fmt . Sprintf ( "/api/v1/namespaces/default/secrets/test" ) ).
121
+ err = rest .Patch (types .StrategicMergePatchType ).AbsPath ("/api/v1/namespaces/default/secrets/test" ).
123
122
Body (patchBody ).Do (context .TODO ()).Error ()
124
123
if err != nil && ! apierrors .IsBadRequest (err ) {
125
124
t .Errorf ("expected success or bad request err, got %v" , err )
126
125
}
127
126
})
128
127
t .Run ("StrategicMergePatchType should handle a valid patch just under the max limit" , func (t * testing.T ) {
129
128
patchBody := []byte (`{"value":0` + strings .Repeat (" " , 3 * 1024 * 1024 - 100 ) + `}` )
130
- err = rest .Patch (types .StrategicMergePatchType ).AbsPath (fmt . Sprintf ( "/api/v1/namespaces/default/secrets/test" ) ).
129
+ err = rest .Patch (types .StrategicMergePatchType ).AbsPath ("/api/v1/namespaces/default/secrets/test" ).
131
130
Body (patchBody ).Do (context .TODO ()).Error ()
132
131
if err != nil {
133
132
t .Errorf ("unexpected error: %v" , err )
134
133
}
135
134
})
136
135
t .Run ("ApplyPatchType should handle a patch just under the max limit" , func (t * testing.T ) {
137
136
patchBody := []byte (`{"value":` + strings .Repeat ("[" , 3 * 1024 * 1024 / 2 - 100 ) + strings .Repeat ("]" , 3 * 1024 * 1024 / 2 - 100 ) + `}` )
138
- err = rest .Patch (types .ApplyPatchType ).Param ("fieldManager" , "test" ).AbsPath (fmt . Sprintf ( "/api/v1/namespaces/default/secrets/test" ) ).
137
+ err = rest .Patch (types .ApplyPatchType ).Param ("fieldManager" , "test" ).AbsPath ("/api/v1/namespaces/default/secrets/test" ).
139
138
Body (patchBody ).Do (context .TODO ()).Error ()
140
139
if err != nil && ! apierrors .IsBadRequest (err ) {
141
140
t .Errorf ("expected success or bad request err, got %#v" , err )
142
141
}
143
142
})
144
143
t .Run ("ApplyPatchType should handle a valid patch just under the max limit" , func (t * testing.T ) {
145
144
patchBody := []byte (`{"apiVersion":"v1","kind":"Secret"` + strings .Repeat (" " , 3 * 1024 * 1024 - 100 ) + `}` )
146
- err = rest .Patch (types .ApplyPatchType ).Param ("fieldManager" , "test" ).AbsPath (fmt . Sprintf ( "/api/v1/namespaces/default/secrets/test" ) ).
145
+ err = rest .Patch (types .ApplyPatchType ).Param ("fieldManager" , "test" ).AbsPath ("/api/v1/namespaces/default/secrets/test" ).
147
146
Body (patchBody ).Do (context .TODO ()).Error ()
148
147
if err != nil {
149
148
t .Errorf ("unexpected error: %v" , err )
150
149
}
151
150
})
152
151
t .Run ("Delete should limit the request body size" , func (t * testing.T ) {
153
- err = c .Delete ().AbsPath (fmt . Sprintf ( "/api/v1/namespaces/default/secrets/test" ) ).
152
+ err = c .Delete ().AbsPath ("/api/v1/namespaces/default/secrets/test" ).
154
153
Body (hugeData ).Do (context .TODO ()).Error ()
155
154
if err == nil {
156
155
t .Fatalf ("unexpected no error" )
0 commit comments