瀏覽代碼

test fix

Signed-off-by: aiordache <[email protected]>
aiordache 4 年之前
父節點
當前提交
6458b97089
共有 3 個文件被更改,包括 19 次插入30 次删除
  1. 0 13
      api/context/context.go
  2. 17 15
      cli/main.go
  3. 2 2
      local/e2e/cli-only/e2e_test.go

+ 0 - 13
api/context/context.go

@@ -21,13 +21,11 @@ import (
 
 	"golang.org/x/net/context"
 
-	configfile "github.com/docker/cli/cli/config/configfile"
 	cliflags "github.com/docker/cli/cli/flags"
 )
 
 type currentContextKey struct{}
 type cliOptionsKey struct{}
-type configKey struct{}
 
 // WithCurrentContext sets the name of the current docker context
 func WithCurrentContext(ctx gocontext.Context, contextName string) context.Context {
@@ -50,14 +48,3 @@ func CliOptions(ctx context.Context) cliflags.CommonOptions {
 	cc, _ := ctx.Value(cliOptionsKey{}).(cliflags.CommonOptions)
 	return cc
 }
-
-// WithConfig sets docker config
-func WithConfig(ctx gocontext.Context, config configfile.ConfigFile) context.Context {
-	return context.WithValue(ctx, configKey{}, config)
-}
-
-// Config returns the docker config
-func Config(ctx context.Context) configfile.ConfigFile {
-	cc, _ := ctx.Value(cliOptionsKey{}).(configfile.ConfigFile)
-	return cc
-}

+ 17 - 15
cli/main.go

@@ -195,10 +195,6 @@ func main() {
 	ctx = config.WithDir(ctx, configDir)
 
 	currentContext := determineCurrentContext(opts.Context, configDir)
-	if len(opts.Hosts) > 0 {
-		opts.Context = ""
-		currentContext = "default"
-	}
 
 	s, err := store.New(configDir)
 	if err != nil {
@@ -216,20 +212,26 @@ func main() {
 		compose.Command(ctype),
 		volume.Command(ctype),
 	)
+	if ctype == store.LocalContextType {
+		if len(opts.Hosts) > 0 {
+			opts.Context = ""
+			currentContext = "default"
+		}
 
-	cnxOptions := cliflags.CommonOptions{
-		Context:   opts.Context,
-		Debug:     opts.Debug,
-		Hosts:     opts.Hosts,
-		LogLevel:  opts.LogLevel,
-		TLS:       opts.TLS,
-		TLSVerify: opts.TLSVerify,
-	}
+		cnxOptions := cliflags.CommonOptions{
+			Context:   opts.Context,
+			Debug:     opts.Debug,
+			Hosts:     opts.Hosts,
+			LogLevel:  opts.LogLevel,
+			TLS:       opts.TLS,
+			TLSVerify: opts.TLSVerify,
+		}
 
-	if opts.TLSVerify {
-		cnxOptions.TLSOptions = opts.TLSOptions
+		if opts.TLSVerify {
+			cnxOptions.TLSOptions = opts.TLSOptions
+		}
+		ctx = apicontext.WithCliOptions(ctx, cnxOptions)
 	}
-	ctx = apicontext.WithCliOptions(ctx, cnxOptions)
 	ctx = apicontext.WithCurrentContext(ctx, currentContext)
 	ctx = store.WithContextStore(ctx, s)
 

+ 2 - 2
local/e2e/cli-only/e2e_test.go

@@ -396,15 +396,15 @@ func TestLegacy(t *testing.T) {
 	})
 
 	t.Run("host flag", func(t *testing.T) {
-		stderr := "nonexistent: Name or service not known"
+		stderr := "dial tcp: lookup nonexistent"
 		if runtime.GOOS == "windows" {
 			stderr = "error during connect: Get http://nonexitent:123"
 		}
 		res := c.RunDockerOrExitError("-H", "tcp://nonexistent:123", "version")
 		res.Assert(t, icmd.Expected{
 			ExitCode: 1,
-			Err:      stderr,
 		})
+		assert.Assert(t, strings.Contains(res.Stderr(), stderr), res.Stderr())
 	})
 
 	t.Run("existing contexts delegate", func(t *testing.T) {