MCPcopy
hub / github.com/docker/compose / TestVersionCommand

Function TestVersionCommand

cmd/compose/version_test.go:31–77  ·  cmd/compose/version_test.go::TestVersionCommand
(t *testing.T)

Source from the content-addressed store, hash-verified

29)
30
31func TestVersionCommand(t *testing.T) {
32 originalVersion := internal.Version
33 defer func() {
34 internal.Version = originalVersion
35 }()
36 internal.Version = "v9.9.9-test"
37
38 tests := []struct {
39 name string
40 args []string
41 want string
42 }{
43 {
44 name: "default",
45 args: []string{},
46 want: "Docker Compose version v9.9.9-test\n",
47 },
48 {
49 name: "short flag",
50 args: []string{"--short"},
51 want: "9.9.9-test\n",
52 },
53 {
54 name: "json flag",
55 args: []string{"--format", "json"},
56 want: `{"version":"v9.9.9-test"}` + "\n",
57 },
58 }
59
60 for _, test := range tests {
61 t.Run(test.name, func(t *testing.T) {
62 ctrl := gomock.NewController(t)
63 defer ctrl.Finish()
64
65 buf := new(bytes.Buffer)
66 cli := mocks.NewMockCli(ctrl)
67 cli.EXPECT().Out().Return(streams.NewOut(buf)).AnyTimes()
68
69 cmd := versionCommand(cli)
70 cmd.SetArgs(test.args)
71 err := cmd.Execute()
72 assert.NilError(t, err)
73
74 assert.Equal(t, test.want, buf.String())
75 })
76 }
77}

Callers

nothing calls this directly

Calls 5

EXPECTMethod · 0.95
NewMockCliFunction · 0.92
versionCommandFunction · 0.85
OutMethod · 0.45
StringMethod · 0.45

Tested by

no test coverage detected