@@ -2037,44 +2037,60 @@ func TestUnsupportedMediaTypeCircuitBreaker(t *testing.T) {
2037
2037
server := kubeapiservertesting .StartTestServerOrDie (t , nil , framework .DefaultTestServerFlags (), framework .SharedEtcd ())
2038
2038
t .Cleanup (server .TearDownFn )
2039
2039
2040
- config := rest .CopyConfig (server .ClientConfig )
2041
- config .ContentType = "application/cbor"
2042
- config .AcceptContentTypes = "application/json"
2040
+ for _ , tc := range []struct {
2041
+ name string
2042
+ contentType string
2043
+ }{
2044
+ {
2045
+ name : "default content type" ,
2046
+ contentType : "" ,
2047
+ },
2048
+ {
2049
+ name : "explicit content type" ,
2050
+ contentType : "application/cbor" ,
2051
+ },
2052
+ } {
2053
+ t .Run (tc .name , func (t * testing.T ) {
2054
+ config := rest .CopyConfig (server .ClientConfig )
2055
+ config .ContentType = tc .contentType
2056
+ config .AcceptContentTypes = "application/json"
2043
2057
2044
- client , err := corev1client .NewForConfig (config )
2045
- if err != nil {
2046
- t .Fatal (err )
2047
- }
2058
+ client , err := corev1client .NewForConfig (config )
2059
+ if err != nil {
2060
+ t .Fatal (err )
2061
+ }
2048
2062
2049
- if _ , err := client .Namespaces ().Create (
2050
- context .TODO (),
2051
- & v1.Namespace {ObjectMeta : metav1.ObjectMeta {Name : "test-client-415" }},
2052
- metav1.CreateOptions {DryRun : []string {metav1 .DryRunAll }},
2053
- ); ! apierrors .IsUnsupportedMediaType (err ) {
2054
- t .Errorf ("expected to receive unsupported media type on first cbor request, got: %v" , err )
2055
- }
2063
+ if _ , err := client .Namespaces ().Create (
2064
+ context .TODO (),
2065
+ & v1.Namespace {ObjectMeta : metav1.ObjectMeta {Name : "test-client-415" }},
2066
+ metav1.CreateOptions {DryRun : []string {metav1 .DryRunAll }},
2067
+ ); ! apierrors .IsUnsupportedMediaType (err ) {
2068
+ t .Errorf ("expected to receive unsupported media type on first cbor request, got: %v" , err )
2069
+ }
2056
2070
2057
- // Requests from this client should fall back from application/cbor to application/json.
2058
- if _ , err := client .Namespaces ().Create (
2059
- context .TODO (),
2060
- & v1.Namespace {ObjectMeta : metav1.ObjectMeta {Name : "test-client-415" }},
2061
- metav1.CreateOptions {DryRun : []string {metav1 .DryRunAll }},
2062
- ); err != nil {
2063
- t .Errorf ("expected to receive nil error on subsequent cbor request, got: %v" , err )
2064
- }
2071
+ // Requests from this client should fall back from application/cbor to application/json.
2072
+ if _ , err := client .Namespaces ().Create (
2073
+ context .TODO (),
2074
+ & v1.Namespace {ObjectMeta : metav1.ObjectMeta {Name : "test-client-415" }},
2075
+ metav1.CreateOptions {DryRun : []string {metav1 .DryRunAll }},
2076
+ ); err != nil {
2077
+ t .Errorf ("expected to receive nil error on subsequent cbor request, got: %v" , err )
2078
+ }
2065
2079
2066
- // The circuit breaker trips on a per-client basis, so it should not begin tripped for a
2067
- // fresh client with identical config.
2068
- client , err = corev1client .NewForConfig (config )
2069
- if err != nil {
2070
- t .Fatal (err )
2071
- }
2080
+ // The circuit breaker trips on a per-client basis, so it should not begin tripped for a
2081
+ // fresh client with identical config.
2082
+ client , err = corev1client .NewForConfig (config )
2083
+ if err != nil {
2084
+ t .Fatal (err )
2085
+ }
2072
2086
2073
- if _ , err := client .Namespaces ().Create (
2074
- context .TODO (),
2075
- & v1.Namespace {ObjectMeta : metav1.ObjectMeta {Name : "test-client-415" }},
2076
- metav1.CreateOptions {DryRun : []string {metav1 .DryRunAll }},
2077
- ); ! apierrors .IsUnsupportedMediaType (err ) {
2078
- t .Errorf ("expected to receive unsupported media type on cbor request with fresh client, got: %v" , err )
2087
+ if _ , err := client .Namespaces ().Create (
2088
+ context .TODO (),
2089
+ & v1.Namespace {ObjectMeta : metav1.ObjectMeta {Name : "test-client-415" }},
2090
+ metav1.CreateOptions {DryRun : []string {metav1 .DryRunAll }},
2091
+ ); ! apierrors .IsUnsupportedMediaType (err ) {
2092
+ t .Errorf ("expected to receive unsupported media type on cbor request with fresh client, got: %v" , err )
2093
+ }
2094
+ })
2079
2095
}
2080
2096
}
0 commit comments