Files
buildx/driver/kubernetes/context/load_test.go
T
Sebastiaan van Stijn 1126d853a8 driver/kubernetes/context: don't use ResolveDefaultContext in test
The ResolveDefaultContext function is only used internally by the CLI,
and has no known external users, except for this test in buildx. It was
exported in [cli@f820766] to allow (unit) testing, but did not document
that it was only exported for this purpose.

This patch rewrites the test to allow deprecating / removing the function
in the CLI.

[cli@f820766]: https://github.com/docker/cli/commit/f820766f6ac57188d96c9ca377f2b4627e90da28

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-10-01 11:31:09 +02:00

46 lines
1.4 KiB
Go

package context
import (
"testing"
"github.com/docker/cli/cli/command"
"github.com/docker/cli/cli/config"
"github.com/docker/cli/cli/context/store"
cliflags "github.com/docker/cli/cli/flags"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestDefaultContextInitializer(t *testing.T) {
t.Setenv("KUBECONFIG", "./fixtures/test-kubeconfig")
dockerCLI, err := command.NewDockerCli()
require.NoError(t, err)
// FIXME(thaJeztah): the context-store is not initialized until "Initialize" is called.
err = dockerCLI.Initialize(cliflags.NewClientOptions())
require.NoError(t, err)
cs := dockerCLI.ContextStore()
assert.NotNil(t, cs)
meta, err := cs.GetMetadata(command.DefaultContextName)
require.NoError(t, err)
assert.Equal(t, "default", meta.Name)
assert.Equal(t, "zoinx", meta.Endpoints[KubernetesEndpoint].(EndpointMeta).DefaultNamespace)
}
func TestConfigFromEndpoint(t *testing.T) {
t.Setenv("KUBECONFIG", "./fixtures/test-kubeconfig")
cfg, err := ConfigFromEndpoint(
"kubernetes:///buildx-test-4c972a3f9d369614b40f28a281790c7e?deployment=buildkit-4c2ed3ed-970f-4f3d-a6df-a4fcbab4d5cf-d9d73&kubeconfig=.%2Ffixtures%2Fk3s-kubeconfig",
store.New(config.ContextStoreDir(), command.DefaultContextStoreConfig()),
)
require.NoError(t, err)
rawcfg, err := cfg.RawConfig()
require.NoError(t, err)
ctxcfg := "k3s"
if _, ok := rawcfg.Contexts[ctxcfg]; !ok {
t.Errorf("Context config %q not found", ctxcfg)
}
}