cli/command: move TestExperimentalCLI to cli/config

This test was only testing whether we could load a legacy config-file that
contained the "experimental" (experimental CLI) option. Experimental cli
options are disabled since 977d3ae046ec6c64be8788a8712251ed547a2bdb (20.10),
and now enabled by default, but we should not fail to start the cli if the
config-file contains the option.

Move the test to the config package, as it doesn't need the cli for this.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
Sebastiaan van Stijn 2025-04-01 12:30:53 +02:00
parent 33494921b8
commit 0dabdd1a0d
No known key found for this signature in database
GPG Key ID: 76698F39D527CE8C
2 changed files with 26 additions and 42 deletions

View File

@ -9,7 +9,6 @@ import (
"net"
"net/http"
"net/http/httptest"
"os"
"path/filepath"
"runtime"
"strings"
@ -19,7 +18,6 @@ import (
"github.com/docker/cli/cli/config"
"github.com/docker/cli/cli/config/configfile"
"github.com/docker/cli/cli/flags"
"github.com/docker/cli/cli/streams"
"github.com/docker/docker/api"
"github.com/docker/docker/api/types"
"github.com/docker/docker/client"
@ -256,46 +254,6 @@ func TestInitializeFromClientHangs(t *testing.T) {
}
}
// The CLI no longer disables/hides experimental CLI features, however, we need
// to verify that existing configuration files do not break
func TestExperimentalCLI(t *testing.T) {
defaultVersion := "v1.55"
testcases := []struct {
doc string
configfile string
}{
{
doc: "default",
configfile: `{}`,
},
{
doc: "experimental",
configfile: `{
"experimental": "enabled"
}`,
},
}
for _, tc := range testcases {
t.Run(tc.doc, func(t *testing.T) {
dir := fs.NewDir(t, tc.doc, fs.WithFile("config.json", tc.configfile))
defer dir.Remove()
apiclient := &fakeClient{
version: defaultVersion,
pingFunc: func() (types.Ping, error) {
return types.Ping{Experimental: true, OSType: "linux", APIVersion: defaultVersion}, nil
},
}
cli := &DockerCli{client: apiclient, err: streams.NewOut(os.Stderr)}
config.SetDir(dir.Path())
err := cli.Initialize(flags.NewClientOptions())
assert.NilError(t, err)
})
}
}
func TestNewDockerCliAndOperators(t *testing.T) {
// Test default operations and also overriding default ones
cli, err := NewDockerCli(WithInputStream(io.NopCloser(strings.NewReader("some input"))))

View File

@ -398,6 +398,32 @@ func TestLoadDefaultConfigFile(t *testing.T) {
})
}
// The CLI no longer disables/hides experimental CLI features, however, we need
// to verify that existing configuration files do not break
func TestLoadLegacyExperimental(t *testing.T) {
tests := []struct {
doc string
configfile string
}{
{
doc: "default",
configfile: `{}`,
},
{
doc: "experimental",
configfile: `{
"experimental": "enabled"
}`,
},
}
for _, tc := range tests {
t.Run(tc.doc, func(t *testing.T) {
_, err := LoadFromReader(strings.NewReader(tc.configfile))
assert.NilError(t, err)
})
}
}
func TestConfigPath(t *testing.T) {
oldDir := Dir()