From 0dabdd1a0d250eb8fbad28992c13763dabffba5d Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Tue, 1 Apr 2025 12:30:53 +0200 Subject: [PATCH] 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 --- cli/command/cli_test.go | 42 --------------------------------------- cli/config/config_test.go | 26 ++++++++++++++++++++++++ 2 files changed, 26 insertions(+), 42 deletions(-) diff --git a/cli/command/cli_test.go b/cli/command/cli_test.go index 5474d3e561..9a51a3fbcd 100644 --- a/cli/command/cli_test.go +++ b/cli/command/cli_test.go @@ -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")))) diff --git a/cli/config/config_test.go b/cli/config/config_test.go index 0d0edfa1e1..922641a726 100644 --- a/cli/config/config_test.go +++ b/cli/config/config_test.go @@ -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()