mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-22 10:06:15 +00:00
Test response content negotiation with CBOR enablement.
This commit is contained in:
parent
a15840a34b
commit
f831368428
@ -1360,7 +1360,7 @@ func TestExtractModifyApply_ForceOwnership(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestGeneratedClientCBOREnablement(t *testing.T) {
|
||||
func TestClientCBOREnablement(t *testing.T) {
|
||||
// Generated clients for built-in types force Protobuf by default. They are tested here to
|
||||
// ensure that the CBOR client feature gates do not interfere with this.
|
||||
DoRequestWithProtobufPreferredGeneratedClient := func(t *testing.T, config *rest.Config) error {
|
||||
@ -1400,6 +1400,34 @@ func TestGeneratedClientCBOREnablement(t *testing.T) {
|
||||
return err
|
||||
}
|
||||
|
||||
DoRequestWithGenericTypedClient := func(t *testing.T, config *rest.Config) error {
|
||||
clientset, err := clientset.NewForConfig(config)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
// Generated clients for built-in types include the PreferProtobuf option, which
|
||||
// forces Protobuf encoding on a per-request basis.
|
||||
client := gentype.NewClientWithListAndApply[*v1.Namespace, *v1.NamespaceList, *corev1ac.NamespaceApplyConfiguration](
|
||||
"namespaces",
|
||||
clientset.CoreV1().RESTClient(),
|
||||
clientscheme.ParameterCodec,
|
||||
"",
|
||||
func() *v1.Namespace { return &v1.Namespace{} },
|
||||
func() *v1.NamespaceList { return &v1.NamespaceList{} },
|
||||
)
|
||||
_, err = client.Create(
|
||||
context.TODO(),
|
||||
&v1.Namespace{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Name: "test-generic-client-cbor-enablement",
|
||||
},
|
||||
},
|
||||
metav1.CreateOptions{DryRun: []string{metav1.DryRunAll}},
|
||||
)
|
||||
return err
|
||||
}
|
||||
|
||||
type testCase struct {
|
||||
name string
|
||||
served bool
|
||||
@ -1592,6 +1620,62 @@ func TestGeneratedClientCBOREnablement(t *testing.T) {
|
||||
wantStatusError: false,
|
||||
doRequest: DoRequestWithGeneratedClient,
|
||||
},
|
||||
{
|
||||
name: "generated client accept cbor and json and protobuf get protobuf",
|
||||
served: true,
|
||||
allowed: true,
|
||||
preferred: false,
|
||||
configuredContentType: "application/json",
|
||||
configuredAccept: "application/vnd.kubernetes.protobuf;q=1,application/cbor;q=0.9,application/json;q=0.8",
|
||||
wantRequestContentType: "application/json",
|
||||
wantRequestAccept: "application/vnd.kubernetes.protobuf;q=1,application/cbor;q=0.9,application/json;q=0.8",
|
||||
wantResponseContentType: "application/vnd.kubernetes.protobuf",
|
||||
wantResponseStatus: http.StatusCreated,
|
||||
wantStatusError: false,
|
||||
doRequest: DoRequestWithGenericTypedClient,
|
||||
},
|
||||
{
|
||||
name: "generated client accept cbor and json get cbor",
|
||||
served: true,
|
||||
allowed: true,
|
||||
preferred: false,
|
||||
configuredContentType: "application/json",
|
||||
configuredAccept: "application/cbor;q=1,application/json;q=0.9",
|
||||
wantRequestContentType: "application/json",
|
||||
wantRequestAccept: "application/cbor;q=1,application/json;q=0.9",
|
||||
wantResponseContentType: "application/cbor",
|
||||
wantResponseStatus: http.StatusCreated,
|
||||
wantStatusError: false,
|
||||
doRequest: DoRequestWithGenericTypedClient,
|
||||
},
|
||||
{
|
||||
name: "generated client accept cbor and json get json cbor not served",
|
||||
served: false,
|
||||
allowed: true,
|
||||
preferred: false,
|
||||
configuredContentType: "application/json",
|
||||
configuredAccept: "application/cbor;q=1,application/json;q=0.9",
|
||||
wantRequestContentType: "application/json",
|
||||
wantRequestAccept: "application/cbor;q=1,application/json;q=0.9",
|
||||
wantResponseContentType: "application/json",
|
||||
wantResponseStatus: http.StatusCreated,
|
||||
wantStatusError: false,
|
||||
doRequest: DoRequestWithGenericTypedClient,
|
||||
},
|
||||
{
|
||||
name: "generated client accept cbor and json get json",
|
||||
served: true,
|
||||
allowed: true,
|
||||
preferred: false,
|
||||
configuredContentType: "application/json",
|
||||
configuredAccept: "application/cbor;q=0.9,application/json;q=1",
|
||||
wantRequestContentType: "application/json",
|
||||
wantRequestAccept: "application/cbor;q=0.9,application/json;q=1",
|
||||
wantResponseContentType: "application/json",
|
||||
wantResponseStatus: http.StatusCreated,
|
||||
wantStatusError: false,
|
||||
doRequest: DoRequestWithGenericTypedClient,
|
||||
},
|
||||
}
|
||||
|
||||
for _, served := range []bool{true, false} {
|
||||
|
Loading…
Reference in New Issue
Block a user