package real

import (
	"os"
	"path/filepath"
	"testing"
)

func TestKubeconfigGetterOverridesNamespace(t *testing.T) {
	t.Parallel()

	kubeconfigPath := filepath.Join(t.TempDir(), "kubeconfig")
	kubeconfig := `apiVersion: v1
kind: Config
clusters:
- cluster:
    server: https://127.0.0.1:6443
  name: test
contexts:
- context:
    cluster: test
    user: test
  name: test
current-context: test
users:
- name: test
  user:
    token: test
`
	if err := os.WriteFile(kubeconfigPath, []byte(kubeconfig), 0600); err != nil {
		t.Fatalf("failed to write kubeconfig: %v", err)
	}
	getter := &kubeconfigGetter{
		kubeconfigPath: kubeconfigPath,
		namespace:      "ocdp-u-alice",
	}

	namespace, _, err := getter.ToRawKubeConfigLoader().Namespace()
	if err != nil {
		t.Fatalf("Namespace returned error: %v", err)
	}
	if namespace != "ocdp-u-alice" {
		t.Fatalf("expected namespace override %q, got %q", "ocdp-u-alice", namespace)
	}
}
