Skip to content

Commit

Permalink
fix: Fix unpopulated discovery client and add test for same
Browse files Browse the repository at this point in the history
  • Loading branch information
stepanstipl committed Nov 18, 2021
1 parent 5595693 commit f3c7a85
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
2 changes: 1 addition & 1 deletion pkg/collector/kube.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ func newKubeCollector(kubeconfig string, kubecontext string, discoveryClient dis
return nil, fmt.Errorf("failed to assemble client config: %w", err)
}

if discoveryClient, err = discovery.NewDiscoveryClientForConfig(col.restConfig); err != nil {
if col.discoveryClient, err = discovery.NewDiscoveryClientForConfig(col.restConfig); err != nil {
return nil, fmt.Errorf("failed to create client: %w", err)
}
}
Expand Down
17 changes: 17 additions & 0 deletions pkg/collector/kube_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,23 @@ func TestNewKubeCollector(t *testing.T) {
}
}

func TestNewKubeCollectorWithKubeconfigPath(t *testing.T) {
col, err := newKubeCollector(filepath.Join(FIXTURES_DIR, "kube.config.basic"), "", nil)

if err != nil {
t.Fatalf("Failed to create kubeCollector from fake discovery client")
}
if col == nil {
t.Fatalf("Should return collector, got nil instead")
}
if col.discoveryClient == nil {
t.Fatalf("Collector should have discovery client, got nil instead")
}
if col.restConfig == nil {
t.Fatalf("Collector should have rest config, got nil instead")
}
}

func TestNewKubeCollectorError(t *testing.T) {
_, err := newKubeCollector("does-not-exist", "", nil)

Expand Down

0 comments on commit f3c7a85

Please sign in to comment.