Skip to content

Commit cb9f296

Browse files
authored
test(mcp): speed up tests by not setting the fake kubeconfig master to example.com
Signed-off-by: Marc Nuri <[email protected]>
1 parent f6e9702 commit cb9f296

File tree

3 files changed

+9
-13
lines changed

3 files changed

+9
-13
lines changed

pkg/kubernetes/openshift.go

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,15 @@ package kubernetes
22

33
import (
44
"context"
5-
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
5+
66
"k8s.io/apimachinery/pkg/runtime/schema"
77
)
88

9-
func (m *Manager) IsOpenShift(ctx context.Context) bool {
9+
func (m *Manager) IsOpenShift(_ context.Context) bool {
1010
// This method should be fast and not block (it's called at startup)
11-
timeoutSeconds := int64(5)
12-
if _, err := m.dynamicClient.Resource(schema.GroupVersionResource{
13-
Group: "project.openshift.io",
14-
Version: "v1",
15-
Resource: "projects",
16-
}).List(ctx, metav1.ListOptions{Limit: 1, TimeoutSeconds: &timeoutSeconds}); err == nil {
17-
return true
18-
}
19-
return false
11+
_, err := m.discoveryClient.ServerResourcesForGroupVersion(schema.GroupVersion{
12+
Group: "project.openshift.io",
13+
Version: "v1",
14+
}.String())
15+
return err == nil
2016
}

pkg/mcp/common_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ func testCaseWithContext(t *testing.T, mcpCtx *mcpContext, test func(c *mcpConte
184184
func (c *mcpContext) withKubeConfig(rc *rest.Config) *api.Config {
185185
fakeConfig := api.NewConfig()
186186
fakeConfig.Clusters["fake"] = api.NewCluster()
187-
fakeConfig.Clusters["fake"].Server = "https://example.com"
187+
fakeConfig.Clusters["fake"].Server = "https://127.0.0.1:6443"
188188
fakeConfig.Clusters["additional-cluster"] = api.NewCluster()
189189
fakeConfig.AuthInfos["fake"] = api.NewAuthInfo()
190190
fakeConfig.AuthInfos["additional-auth"] = api.NewAuthInfo()

pkg/mcp/configuration_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ func TestConfigurationView(t *testing.T) {
5050
if decoded.Clusters[0].Name != "fake" {
5151
t.Errorf("fake-cluster not found: %v", decoded.Clusters)
5252
}
53-
if decoded.Clusters[0].Cluster.Server != "https://example.com" {
53+
if decoded.Clusters[0].Cluster.Server != "https://127.0.0.1:6443" {
5454
t.Errorf("fake-server not found: %v", decoded.Clusters)
5555
}
5656
})

0 commit comments

Comments
 (0)