mirror of
https://github.com/docker/compose.git
synced 2026-09-24 14:34:26 +00:00
Rename-only change, no behavior difference, no exported identifier renamed (only parameter names of a few exported functions, which are not part of the Go API). - names that hide what a value is: parameters holding a *name* or *ID* while named like the object — project→projectName, service→serviceName, container→containerID — so string vs struct is readable at every call site without opening the signature - misleading receivers: monitor methods used c (reads as client/container/CLI) → m; jsonWriter used p while its ttyWriter sibling uses w → w - cryptic abbreviations with non-trivial scope: nw (meant both network.Summary and types.NetworkConfig) → network/networkConfig, svc → service/serviceName/serviceCopy, oc/ocs → observedContainer(s), cnts → serviceContainers, cnx → attachResponse - container.Summary loop variables unified on ctr (was a c/ctr mix); fillBindMounts also dropped its p/s/m single-letters, one of which was shadowed by a loop variable of a different type - option-struct identifiers unified on options (opts remains only for variadic functional options); ambiguous ones get a precise name (bindOptions, networkCreateOptions, projectOptionsFns) Signed-off-by: Nicolas De Loof <nicolas.deloof@gmail.com>
43 lines
1.4 KiB
Go
43 lines
1.4 KiB
Go
/*
|
|
Copyright 2022 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 e2e
|
|
|
|
import (
|
|
"encoding/json"
|
|
"strings"
|
|
"testing"
|
|
|
|
"gotest.tools/v3/assert"
|
|
is "gotest.tools/v3/assert/cmp"
|
|
)
|
|
|
|
// RequireServiceState ensures that the container is in the expected state
|
|
// (running or exited).
|
|
func RequireServiceState(t testing.TB, cli *CLI, service string, state string) {
|
|
t.Helper()
|
|
psRes := cli.RunDockerComposeCmd(t, "ps", "--all", "--format=json", service)
|
|
var serviceState map[string]any
|
|
assert.NilError(t, json.Unmarshal([]byte(psRes.Stdout()), &serviceState),
|
|
"Invalid `compose ps` JSON: command output: %s",
|
|
psRes.Combined())
|
|
|
|
assert.Assert(t, is.Equal(service, serviceState["Service"]), "Found ps output for unexpected service")
|
|
assert.Assert(t, is.Equal(strings.ToLower(state), strings.ToLower(serviceState["State"].(string))),
|
|
"Service %q (%s) not in expected state",
|
|
service, serviceState["Name"],
|
|
)
|
|
}
|