Skip to content

Commit c3980f6

Browse files
authored
Merge pull request kubernetes#128267 from benluddy/cbor-response-negotiation
KEP-4222: Test response content negotiation for each CBOR enablement state.
2 parents b8e20b7 + f831368 commit c3980f6

File tree

1 file changed

+85
-1
lines changed

1 file changed

+85
-1
lines changed

test/integration/client/client_test.go

Lines changed: 85 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1360,7 +1360,7 @@ func TestExtractModifyApply_ForceOwnership(t *testing.T) {
13601360
}
13611361
}
13621362

1363-
func TestGeneratedClientCBOREnablement(t *testing.T) {
1363+
func TestClientCBOREnablement(t *testing.T) {
13641364
// Generated clients for built-in types force Protobuf by default. They are tested here to
13651365
// ensure that the CBOR client feature gates do not interfere with this.
13661366
DoRequestWithProtobufPreferredGeneratedClient := func(t *testing.T, config *rest.Config) error {
@@ -1400,6 +1400,34 @@ func TestGeneratedClientCBOREnablement(t *testing.T) {
14001400
return err
14011401
}
14021402

1403+
DoRequestWithGenericTypedClient := func(t *testing.T, config *rest.Config) error {
1404+
clientset, err := clientset.NewForConfig(config)
1405+
if err != nil {
1406+
t.Fatal(err)
1407+
}
1408+
1409+
// Generated clients for built-in types include the PreferProtobuf option, which
1410+
// forces Protobuf encoding on a per-request basis.
1411+
client := gentype.NewClientWithListAndApply[*v1.Namespace, *v1.NamespaceList, *corev1ac.NamespaceApplyConfiguration](
1412+
"namespaces",
1413+
clientset.CoreV1().RESTClient(),
1414+
clientscheme.ParameterCodec,
1415+
"",
1416+
func() *v1.Namespace { return &v1.Namespace{} },
1417+
func() *v1.NamespaceList { return &v1.NamespaceList{} },
1418+
)
1419+
_, err = client.Create(
1420+
context.TODO(),
1421+
&v1.Namespace{
1422+
ObjectMeta: metav1.ObjectMeta{
1423+
Name: "test-generic-client-cbor-enablement",
1424+
},
1425+
},
1426+
metav1.CreateOptions{DryRun: []string{metav1.DryRunAll}},
1427+
)
1428+
return err
1429+
}
1430+
14031431
type testCase struct {
14041432
name string
14051433
served bool
@@ -1592,6 +1620,62 @@ func TestGeneratedClientCBOREnablement(t *testing.T) {
15921620
wantStatusError: false,
15931621
doRequest: DoRequestWithGeneratedClient,
15941622
},
1623+
{
1624+
name: "generated client accept cbor and json and protobuf get protobuf",
1625+
served: true,
1626+
allowed: true,
1627+
preferred: false,
1628+
configuredContentType: "application/json",
1629+
configuredAccept: "application/vnd.kubernetes.protobuf;q=1,application/cbor;q=0.9,application/json;q=0.8",
1630+
wantRequestContentType: "application/json",
1631+
wantRequestAccept: "application/vnd.kubernetes.protobuf;q=1,application/cbor;q=0.9,application/json;q=0.8",
1632+
wantResponseContentType: "application/vnd.kubernetes.protobuf",
1633+
wantResponseStatus: http.StatusCreated,
1634+
wantStatusError: false,
1635+
doRequest: DoRequestWithGenericTypedClient,
1636+
},
1637+
{
1638+
name: "generated client accept cbor and json get cbor",
1639+
served: true,
1640+
allowed: true,
1641+
preferred: false,
1642+
configuredContentType: "application/json",
1643+
configuredAccept: "application/cbor;q=1,application/json;q=0.9",
1644+
wantRequestContentType: "application/json",
1645+
wantRequestAccept: "application/cbor;q=1,application/json;q=0.9",
1646+
wantResponseContentType: "application/cbor",
1647+
wantResponseStatus: http.StatusCreated,
1648+
wantStatusError: false,
1649+
doRequest: DoRequestWithGenericTypedClient,
1650+
},
1651+
{
1652+
name: "generated client accept cbor and json get json cbor not served",
1653+
served: false,
1654+
allowed: true,
1655+
preferred: false,
1656+
configuredContentType: "application/json",
1657+
configuredAccept: "application/cbor;q=1,application/json;q=0.9",
1658+
wantRequestContentType: "application/json",
1659+
wantRequestAccept: "application/cbor;q=1,application/json;q=0.9",
1660+
wantResponseContentType: "application/json",
1661+
wantResponseStatus: http.StatusCreated,
1662+
wantStatusError: false,
1663+
doRequest: DoRequestWithGenericTypedClient,
1664+
},
1665+
{
1666+
name: "generated client accept cbor and json get json",
1667+
served: true,
1668+
allowed: true,
1669+
preferred: false,
1670+
configuredContentType: "application/json",
1671+
configuredAccept: "application/cbor;q=0.9,application/json;q=1",
1672+
wantRequestContentType: "application/json",
1673+
wantRequestAccept: "application/cbor;q=0.9,application/json;q=1",
1674+
wantResponseContentType: "application/json",
1675+
wantResponseStatus: http.StatusCreated,
1676+
wantStatusError: false,
1677+
doRequest: DoRequestWithGenericTypedClient,
1678+
},
15951679
}
15961680

15971681
for _, served := range []bool{true, false} {

0 commit comments

Comments
 (0)