test: cover up remote-stack variable prompt
Some checks failed
ci / validate (lint) (push) Has been cancelled
ci / validate (validate-docs) (push) Has been cancelled
ci / validate (validate-go-mod) (push) Has been cancelled
ci / validate (validate-headers) (push) Has been cancelled
ci / binary (push) Has been cancelled
ci / bin-image-test (push) Has been cancelled
ci / test (push) Has been cancelled
ci / e2e (plugin, oldstable) (push) Has been cancelled
ci / e2e (standalone, oldstable) (push) Has been cancelled
ci / e2e (plugin, stable) (push) Has been cancelled
ci / e2e (standalone, stable) (push) Has been cancelled
merge / bin-image-prepare (push) Has been cancelled
merge / module-image (push) Has been cancelled
Scorecards supply-chain security / Scorecards analysis (push) Has been cancelled
ci / binary-finalize (push) Has been cancelled
ci / coverage (push) Has been cancelled
ci / release (push) Has been cancelled
merge / bin-image (push) Has been cancelled
merge / desktop-edge-test (push) Has been cancelled

Signed-off-by: bigmomma <scarab.systems@yahoo.com>
This commit is contained in:
bigmomma 2026-06-09 10:14:49 -04:00 committed by Guillaume Lours
parent fc83fbfa9e
commit 6ded3140df
2 changed files with 105 additions and 11 deletions

View file

@ -138,17 +138,18 @@ func Adapt(fn Command) func(cmd *cobra.Command, args []string) error {
}
type ProjectOptions struct {
ProjectName string
Profiles []string
ConfigPaths []string
WorkDir string
ProjectDir string
EnvFiles []string
Compatibility bool
Progress string
Offline bool
All bool
insecureRegistries []string
ProjectName string
Profiles []string
ConfigPaths []string
WorkDir string
ProjectDir string
EnvFiles []string
Compatibility bool
Progress string
Offline bool
All bool
insecureRegistries []string
remoteLoadersOverride []loader.ResourceLoader
}
// ProjectFunc does stuff within a types.Project
@ -361,6 +362,9 @@ func (o *ProjectOptions) ToProject(ctx context.Context, dockerCli command.Cli, b
}
func (o *ProjectOptions) remoteLoaders(dockerCli command.Cli) []loader.ResourceLoader {
if o.remoteLoadersOverride != nil {
return o.remoteLoadersOverride
}
if o.Offline {
return nil
}

View file

@ -17,14 +17,43 @@
package compose
import (
"bytes"
"context"
"fmt"
"io"
"os"
"path/filepath"
"strings"
"testing"
"github.com/compose-spec/compose-go/v2/loader"
"github.com/compose-spec/compose-go/v2/types"
"github.com/docker/cli/cli/streams"
"go.uber.org/mock/gomock"
"gotest.tools/v3/assert"
"github.com/docker/compose/v5/pkg/api"
"github.com/docker/compose/v5/pkg/mocks"
)
type testRemoteLoader struct {
localPath string
}
func (l testRemoteLoader) Accept(path string) bool {
return strings.HasPrefix(path, "test://")
}
func (l testRemoteLoader) Load(context.Context, string) (string, error) {
return l.localPath, nil
}
func (l testRemoteLoader) Dir(string) string {
return filepath.Dir(l.localPath)
}
var _ loader.ResourceLoader = testRemoteLoader{}
func TestApplyScaleOpt(t *testing.T) {
p := types.Project{
Services: types.Services{
@ -89,3 +118,64 @@ func TestUpOptions_OnExit(t *testing.T) {
})
}
}
func TestRunUpAllowsTemplatedPortFieldsInRemoteStackPrompt(t *testing.T) {
ctrl := gomock.NewController(t)
defer ctrl.Finish()
dir := t.TempDir()
composePath := filepath.Join(dir, "compose.yaml")
assert.NilError(t, os.WriteFile(composePath, []byte(`
name: remote-defaults
services:
web:
image: nginx
ports:
- host_ip: "${LXKNS_ADDRESS:-127.0.0.1}"
published: "${LXKNS_PORT:-5010}"
target: 80
protocol: tcp
`), 0o600))
in := io.NopCloser(bytes.NewBufferString("n\n"))
out := new(bytes.Buffer)
errOut := new(bytes.Buffer)
cli := mocks.NewMockCli(ctrl)
cli.EXPECT().In().Return(streams.NewIn(in)).AnyTimes()
cli.EXPECT().Out().Return(streams.NewOut(out)).AnyTimes()
cli.EXPECT().Err().Return(streams.NewOut(errOut)).AnyTimes()
projectOptions := &ProjectOptions{
ConfigPaths: []string{"test://remote/compose.yaml"},
ProjectDir: dir,
remoteLoadersOverride: []loader.ResourceLoader{testRemoteLoader{localPath: composePath}},
}
project := &types.Project{
Name: "remote-defaults",
WorkingDir: dir,
Services: types.Services{
"web": {
Name: "web",
Image: "nginx",
},
},
}
err := runUp(
t.Context(),
cli,
&BackendOptions{},
createOptions{},
upOptions{},
buildOptions{ProjectOptions: projectOptions},
project,
nil,
)
assert.Error(t, err, "operation cancelled by user")
output := out.String()
assert.Assert(t, strings.Contains(output, `Your compose stack "test://remote/compose.yaml"`), output)
assert.Assert(t, strings.Contains(output, "LXKNS_ADDRESS"), output)
assert.Assert(t, strings.Contains(output, "LXKNS_PORT"), output)
assert.Assert(t, !strings.Contains(fmt.Sprint(err), "invalid ip address"), fmt.Sprint(err))
}