-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Expand file tree
/
Copy pathbuilder_windows_test.go
More file actions
61 lines (49 loc) · 1.45 KB
/
builder_windows_test.go
File metadata and controls
61 lines (49 loc) · 1.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
package main
import (
"bytes"
"context"
"errors"
"os"
"testing"
"github.com/docker/cli/cli/command"
"github.com/docker/cli/cli/flags"
"github.com/moby/moby/client"
"gotest.tools/v3/assert"
"gotest.tools/v3/fs"
)
func init() {
pluginFilename = pluginFilename + ".exe"
}
type failingPingClient struct {
client.Client
}
func (*failingPingClient) Ping(context.Context, client.PingOptions) (client.PingResult, error) {
return client.PingResult{}, errors.New("daemon unavailable")
}
func TestBuildWithUnavailableDaemonUsesWindowsLegacyDefault(t *testing.T) {
ctx := t.Context()
dir := fs.NewDir(t, t.Name(),
fs.WithFile(pluginFilename, `#!/bin/sh exit 1`, fs.WithMode(0o777)),
)
defer dir.Remove()
b := bytes.NewBuffer(nil)
dockerCli, err := command.NewDockerCli(
command.WithBaseContext(ctx),
command.WithAPIClient(&failingPingClient{}),
command.WithInputStream(discard),
command.WithCombinedStreams(b),
)
assert.NilError(t, err)
assert.NilError(t, dockerCli.Initialize(flags.NewClientOptions()))
dockerCli.ConfigFile().CLIPluginsExtraDirs = []string{dir.Path()}
tcmd := newDockerCommand(dockerCli)
tcmd.SetArgs([]string{"build", "."})
cmd, args, err := tcmd.HandleGlobalFlags()
assert.NilError(t, err)
var envs []string
args, os.Args, envs, err = processBuilder(dockerCli, cmd, args, os.Args)
assert.NilError(t, err)
assert.DeepEqual(t, []string{"build", "."}, args)
assert.Check(t, len(envs) == 0)
assert.Equal(t, b.String(), "")
}