Skip to content

Commit 90c2802

Browse files
committed
fix(test): reset kube config location for each test
1 parent d375458 commit 90c2802

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

pkg/mcp/common_test.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ func (c *mcpContext) beforeEach(t *testing.T) {
8989
var err error
9090
c.ctx, c.cancel = context.WithCancel(context.Background())
9191
c.tempDir = t.TempDir()
92-
_ = os.Unsetenv("KUBECONFIG")
92+
c.withKubeConfig(nil)
9393
if c.mcpServer, err = NewSever(); err != nil {
9494
t.Fatal(err)
9595
return
@@ -99,7 +99,6 @@ func (c *mcpContext) beforeEach(t *testing.T) {
9999
t.Fatal(err)
100100
return
101101
}
102-
c.withKubeConfig(nil)
103102
if err = c.mcpClient.Start(c.ctx); err != nil {
104103
t.Fatal(err)
105104
return
@@ -146,8 +145,10 @@ func (c *mcpContext) withKubeConfig(rc *rest.Config) *api.Config {
146145
kubeConfig := filepath.Join(c.tempDir, "config")
147146
_ = clientcmd.WriteToFile(*fakeConfig, kubeConfig)
148147
_ = os.Setenv("KUBECONFIG", kubeConfig)
149-
if err := c.mcpServer.reloadKubernetesClient(); err != nil {
150-
panic(err)
148+
if c.mcpServer != nil {
149+
if err := c.mcpServer.reloadKubernetesClient(); err != nil {
150+
panic(err)
151+
}
151152
}
152153
return fakeConfig
153154
}

0 commit comments

Comments
 (0)