Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pkg/http/http_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ func (c *httpContext) beforeEach(t *testing.T) {
mockKubeConfig := c.mockServer.KubeConfig()
kubeConfig := filepath.Join(t.TempDir(), "config")
_ = clientcmd.WriteToFile(*mockKubeConfig, kubeConfig)
_ = os.Setenv("KUBECONFIG", kubeConfig)
c.StaticConfig.KubeConfig = kubeConfig
// Capture logging
c.klogState = klog.CaptureState()
flags := flag.NewFlagSet("test", flag.ContinueOnError)
Expand Down
19 changes: 19 additions & 0 deletions pkg/kubernetes/common_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package kubernetes

import (
"os"
"testing"
)

func TestMain(m *testing.M) {
// Set up
_ = os.Setenv("KUBECONFIG", "/dev/null") // Avoid interference from existing kubeconfig
_ = os.Setenv("KUBERNETES_SERVICE_HOST", "") // Avoid interference from in-cluster config
_ = os.Setenv("KUBERNETES_SERVICE_PORT", "") // Avoid interference from in-cluster config

// Run tests
code := m.Run()

// Tear down
os.Exit(code)
}
3 changes: 3 additions & 0 deletions pkg/mcp/common_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ var envTestUser = envtest.User{Name: "test-user", Groups: []string{"test:users"}

func TestMain(m *testing.M) {
// Set up
_ = os.Setenv("KUBECONFIG", "/dev/null") // Avoid interference from existing kubeconfig
_ = os.Setenv("KUBERNETES_SERVICE_HOST", "") // Avoid interference from in-cluster config
_ = os.Setenv("KUBERNETES_SERVICE_PORT", "") // Avoid interference from in-cluster config
envTestDir, err := store.DefaultStoreDir()
if err != nil {
panic(err)
Expand Down
5 changes: 3 additions & 2 deletions pkg/mcp/configuration_test.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
package mcp

import (
"testing"

"github.com/containers/kubernetes-mcp-server/pkg/kubernetes"
"github.com/mark3labs/mcp-go/mcp"
"k8s.io/client-go/rest"
v1 "k8s.io/client-go/tools/clientcmd/api/v1"
"sigs.k8s.io/yaml"
"testing"
)

func TestConfigurationView(t *testing.T) {
Expand Down Expand Up @@ -78,7 +79,7 @@ func TestConfigurationView(t *testing.T) {
})
t.Run("configuration_view with minified=false returns additional context info", func(t *testing.T) {
if len(decoded.Contexts) != 2 {
t.Errorf("invalid context count, expected2, got %v", len(decoded.Contexts))
t.Fatalf("invalid context count, expected2, got %v", len(decoded.Contexts))
}
if decoded.Contexts[0].Name != "additional-context" {
t.Errorf("additional-context not found: %v", decoded.Contexts)
Expand Down
Loading