Commit e69475d2 authored by Madhusudan.C.S's avatar Madhusudan.C.S

Make the fake command factory return the clientset with appropriate rest clients…

Make the fake command factory return the clientset with appropriate rest clients for all the API groups. Calling `internalclientset.New()` with a rest client as an argument simply copies that rest client to all the API group clients irrespective of the configured GroupVersion or versionedAPIPath in the client. So only one API group client gets the client configured correctly for that API group. All the other API group clients get misconfigured rest clients. On the other hand, `internalclientset.NewForConfigOrDie()` does the right thing by reconfiguring the passed configs for each API group and initializes an appropriate rest client for that group. Now that we are relying on the `NewForConfigOrDie()` method to initialize the rest clients, we need to swap the underlying http clients in each of these rest clients with a fake one for testing.
parent 7760c2f5
...@@ -413,14 +413,23 @@ func (f *fakeAPIFactory) JSONEncoder() runtime.Encoder { ...@@ -413,14 +413,23 @@ func (f *fakeAPIFactory) JSONEncoder() runtime.Encoder {
} }
func (f *fakeAPIFactory) ClientSet() (*internalclientset.Clientset, error) { func (f *fakeAPIFactory) ClientSet() (*internalclientset.Clientset, error) {
// Swap out the HTTP client out of the client with the fake's version. // Swap the HTTP client out of the REST client with the fake
// version.
fakeClient := f.tf.Client.(*fake.RESTClient) fakeClient := f.tf.Client.(*fake.RESTClient)
restClient, err := restclient.RESTClientFor(f.tf.ClientConfig) clientset := internalclientset.NewForConfigOrDie(f.tf.ClientConfig)
if err != nil { clientset.CoreClient.RESTClient.Client = fakeClient.Client
panic(err) clientset.AuthenticationClient.RESTClient.Client = fakeClient.Client
} clientset.AuthorizationClient.RESTClient.Client = fakeClient.Client
restClient.Client = fakeClient.Client clientset.AutoscalingClient.RESTClient.Client = fakeClient.Client
return internalclientset.New(restClient), f.tf.Err clientset.BatchClient.RESTClient.Client = fakeClient.Client
clientset.CertificatesClient.RESTClient.Client = fakeClient.Client
clientset.ExtensionsClient.RESTClient.Client = fakeClient.Client
clientset.RbacClient.RESTClient.Client = fakeClient.Client
clientset.StorageClient.RESTClient.Client = fakeClient.Client
clientset.AppsClient.RESTClient.Client = fakeClient.Client
clientset.PolicyClient.RESTClient.Client = fakeClient.Client
clientset.DiscoveryClient.RESTClient.Client = fakeClient.Client
return clientset, f.tf.Err
} }
func (f *fakeAPIFactory) RESTClient() (*restclient.RESTClient, error) { func (f *fakeAPIFactory) RESTClient() (*restclient.RESTClient, error) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment