Skip to content

Commit

Permalink
more ut coverage
Browse files Browse the repository at this point in the history
Signed-off-by: AiRanthem <[email protected]>
  • Loading branch information
AiRanthem committed Nov 7, 2024
1 parent 1085611 commit 64d02dd
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 14 deletions.
16 changes: 6 additions & 10 deletions multicluster/remoteclusterclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,10 +113,8 @@ func (in *remoteClusterClient) GetRESTMapper(cluster string) (meta.RESTMapper, e
if item == nil {
copied := rest.CopyConfig(in.config)
copied.Wrap(NewTransportWrapper(ForCluster(cluster)))
httpClient, err := rest.HTTPClientFor(copied)
if err != nil {
return nil, err
}
// this error never happens because rest.HTTPClientFor is already called with the same config in client.New
httpClient, _ := rest.HTTPClientFor(copied)
mapper, err := apiutil.NewDynamicRESTMapper(copied, httpClient)
if err != nil {
return nil, err
Expand Down Expand Up @@ -150,10 +148,8 @@ func (in *remoteClusterClient) GetRESTClient(gvk schema.GroupVersionKind) (rest.
}
item := in.restClients.Get(gvk)
if item == nil {
httpClient, err := rest.HTTPClientFor(in.config)
if err != nil {
return nil, err
}
// this error never happens because rest.HTTPClientFor is already called with the same config in client.New
httpClient, _ := rest.HTTPClientFor(in.config)
restClient, err := apiutil.RESTClientForGVK(gvk, true, in.config, in.codecs, httpClient)
if err != nil {
return nil, err
Expand Down Expand Up @@ -671,11 +667,11 @@ var _ runtime.ParameterCodec = noConversionParamCodec{}
// it's useful in scenarios with the unstructured client and arbitrary resources.
type noConversionParamCodec struct{}

func (noConversionParamCodec) EncodeParameters(obj runtime.Object, to schema.GroupVersion) (url.Values, error) {
func (noConversionParamCodec) EncodeParameters(obj runtime.Object, _ schema.GroupVersion) (url.Values, error) {
return queryparams.Convert(obj)
}

func (noConversionParamCodec) DecodeParameters(parameters url.Values, from schema.GroupVersion, into runtime.Object) error {
func (noConversionParamCodec) DecodeParameters(_ url.Values, _ schema.GroupVersion, _ runtime.Object) error {
return fmt.Errorf("DecodeParameters not implemented on noConversionParamCodec")
}

Expand Down
9 changes: 9 additions & 0 deletions multicluster/remoteclusterclient_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ import (
"github.com/kubevela/pkg/util/k8s"
"github.com/kubevela/pkg/util/rand"
"github.com/kubevela/pkg/util/singleton"
"sigs.k8s.io/controller-runtime/pkg/client"
)

var _ = Describe("Test remote multicluster client", func() {
Expand Down Expand Up @@ -230,3 +231,11 @@ func TestParamCodec(t *testing.T) {
err = paramCodec.DecodeParameters(url.Values{}, schema.GroupVersion{}, nil)
require.Error(t, err)
}

func TestBadConfig(t *testing.T) {
badCfg := rest.Config{
Host: "very bad guy",
}
_, err := multicluster.NewRemoteClusterClient(&badCfg, client.Options{})
require.Error(t, err)
}
5 changes: 1 addition & 4 deletions util/singleton/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,7 @@ var KubeConfig = NewSingleton[*rest.Config](func() *rest.Config {
// RESTMapper .
var RESTMapper = NewSingletonE[meta.RESTMapper](func() (meta.RESTMapper, error) {
config := KubeConfig.Get()
httpClient, err := rest.HTTPClientFor(config)
if err != nil {
return nil, err
}
httpClient, _ := rest.HTTPClientFor(config)
return apiutil.NewDiscoveryRESTMapper(config, httpClient)
})

Expand Down

0 comments on commit 64d02dd

Please sign in to comment.