Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions cmd/compose/bridge.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"io"

"github.com/distribution/reference"
"github.com/docker/cli/cli"
"github.com/docker/cli/cli/command"
"github.com/docker/go-units"
"github.com/moby/moby/api/types/image"
Expand Down Expand Up @@ -51,6 +52,7 @@ func convertCommand(p *ProjectOptions, dockerCli command.Cli) *cobra.Command {
cmd := &cobra.Command{
Use: "convert",
Short: "Convert compose files to Kubernetes manifests, Helm charts, or another model",
Args: cobra.NoArgs,
RunE: Adapt(func(ctx context.Context, args []string) error {
return runConvert(ctx, dockerCli, p, convertOpts)
}),
Expand Down Expand Up @@ -93,6 +95,7 @@ func listTransformersCommand(dockerCli command.Cli) *cobra.Command {
Use: "list",
Aliases: []string{"ls"},
Short: "List available transformations",
Args: cobra.NoArgs,
RunE: Adapt(func(ctx context.Context, args []string) error {
transformers, err := bridge.ListTransformers(ctx, dockerCli)
if err != nil {
Expand Down Expand Up @@ -145,6 +148,7 @@ func createTransformerCommand(dockerCli command.Cli) *cobra.Command {
cmd := &cobra.Command{
Use: "create [OPTION] PATH",
Short: "Create a new transformation",
Args: cli.ExactArgs(1),
RunE: Adapt(func(ctx context.Context, args []string) error {
opts.Dest = args[0]
return bridge.CreateTransformer(ctx, dockerCli, opts)
Expand Down
69 changes: 69 additions & 0 deletions cmd/compose/bridge_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
/*
Copyright 2025 Docker Compose CLI authors

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package compose

import (
"io"
"testing"

"github.com/spf13/cobra"
"gotest.tools/v3/assert"
)

func TestBridgeCommandsArgsValidation(t *testing.T) {
tests := []struct {
name string
cmd *cobra.Command
args []string
wantErr string
}{
{
name: "create requires a PATH argument",
cmd: createTransformerCommand(nil),
args: []string{},
wantErr: "requires 1 argument",
},
{
name: "create rejects extra arguments",
cmd: createTransformerCommand(nil),
args: []string{"dest", "extra"},
wantErr: "requires 1 argument",
},
{
name: "convert rejects arguments",
cmd: convertCommand(&ProjectOptions{}, nil),
args: []string{"extra"},
wantErr: "unknown command",
},
{
name: "list rejects arguments",
cmd: listTransformersCommand(nil),
args: []string{"extra"},
wantErr: "unknown command",
},
}

for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
test.cmd.SetArgs(test.args)
test.cmd.SetOut(io.Discard)
test.cmd.SetErr(io.Discard)
err := test.cmd.Execute()
assert.ErrorContains(t, err, test.wantErr)
})
}
}
Loading