mirror of
https://github.com/docker/compose.git
synced 2026-11-17 13:45:39 +00:00
Production: - detached and interactive up prepare their plan the same way: prepareUp holds the preparation and the --wait-timeout rationale both share, so the two cannot diverge; - useAPISocket leaves alone a project it already transformed. The session, the watcher and the teardown now work on the plan's own project, which a watch rebuild hands to a later plan: transforming it again mounted the socket and the config file twice; - the docs say what the code does: an interruption met while reading the daemon's time is returned wrapping the context's error (the CLI maps it to its interruption exit code), Up ignores StartOptions.Project and does not verify StartOptions.Wait in the foreground, and the Start phase's listener goes through runStart. Tests: - the Start phase is shown to survive the caller's cancellation, and an interruption before it to start nothing; - the dry-run test no longer claims to exercise the dry-run client: it pins the gate of Up; - the phase order test also checks the "up" scope opens before the create; - useAPISocket's idempotence is tested. Signed-off-by: Nicolas De Loof <nicolas.deloof@gmail.com>
58 lines
2.1 KiB
Go
58 lines
2.1 KiB
Go
/*
|
|
Copyright 2026 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 (
|
|
"testing"
|
|
|
|
"github.com/compose-spec/compose-go/v2/types"
|
|
"gotest.tools/v3/assert"
|
|
)
|
|
|
|
// linuxContextInfo is the context of a Linux engine.
|
|
type linuxContextInfo struct{}
|
|
|
|
func (linuxContextInfo) CurrentContext() string { return "default" }
|
|
func (linuxContextInfo) ServerOSType() string { return "linux" }
|
|
func (linuxContextInfo) BuildKitEnabled() (bool, error) { return false, nil }
|
|
|
|
// TestUseAPISocketIsIdempotent verifies that a project which already went
|
|
// through useAPISocket -- the plan's own project, handed to a later plan such
|
|
// as a watch rebuild -- is not transformed a second time: the socket and the
|
|
// config file would be mounted twice.
|
|
func TestUseAPISocketIsIdempotent(t *testing.T) {
|
|
svc, _ := newTestService(t, WithContextInfo(linuxContextInfo{}))
|
|
project := &types.Project{
|
|
Name: "test",
|
|
Services: types.Services{
|
|
"app": {Name: "app", ContainerSpec: types.ContainerSpec{UseAPISocket: true, Environment: types.MappingWithEquals{}}},
|
|
},
|
|
Configs: types.Configs{},
|
|
}
|
|
|
|
once, err := svc.useAPISocket(project)
|
|
assert.NilError(t, err)
|
|
service := once.Services["app"]
|
|
assert.Equal(t, len(service.Volumes), 1, "volumes: %v", service.Volumes)
|
|
assert.Equal(t, len(service.Configs), 1, "configs: %v", service.Configs)
|
|
|
|
twice, err := svc.useAPISocket(once)
|
|
assert.NilError(t, err)
|
|
service = twice.Services["app"]
|
|
assert.Equal(t, len(service.Volumes), 1, "volumes: %v", service.Volumes)
|
|
assert.Equal(t, len(service.Configs), 1, "configs: %v", service.Configs)
|
|
}
|