@@ -1360,7 +1360,7 @@ func TestExtractModifyApply_ForceOwnership(t *testing.T) {
1360
1360
}
1361
1361
}
1362
1362
1363
- func TestGeneratedClientCBOREnablement (t * testing.T ) {
1363
+ func TestClientCBOREnablement (t * testing.T ) {
1364
1364
// Generated clients for built-in types force Protobuf by default. They are tested here to
1365
1365
// ensure that the CBOR client feature gates do not interfere with this.
1366
1366
DoRequestWithProtobufPreferredGeneratedClient := func (t * testing.T , config * rest.Config ) error {
@@ -1400,6 +1400,34 @@ func TestGeneratedClientCBOREnablement(t *testing.T) {
1400
1400
return err
1401
1401
}
1402
1402
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
+
1403
1431
type testCase struct {
1404
1432
name string
1405
1433
served bool
@@ -1592,6 +1620,62 @@ func TestGeneratedClientCBOREnablement(t *testing.T) {
1592
1620
wantStatusError : false ,
1593
1621
doRequest : DoRequestWithGeneratedClient ,
1594
1622
},
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
+ },
1595
1679
}
1596
1680
1597
1681
for _ , served := range []bool {true , false } {
0 commit comments