mirror of
https://github.com/docker/compose.git
synced 2026-11-18 06:07:53 +00:00
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
docs-upstream / docs-yaml (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
docs-upstream / validate (push) Has been cancelled
merge / bin-image (push) Has been cancelled
merge / desktop-edge-test (push) Has been cancelled
Pass the active project name as the appId query parameter on the
docker-desktop://dashboard/logs deep link, both from the post-command
hint (compose up -d, compose logs) and the interactive nav menu
('l' key during compose up). The hook subprocess re-runs compose-go's
project loader so the name matches what the parent computed; it skips
the appId when -p, -f, --project-directory, --workdir, or --env-file
is set, since the hook payload does not carry their values. docker
logs stays unfiltered: the CLI hook contract does not expose the
positional container id.
Signed-off-by: Guillaume Lours <glours@users.noreply.github.com>
90 lines
2.2 KiB
Go
90 lines
2.2 KiB
Go
/*
|
|
Copyright 2024 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 desktop
|
|
|
|
import (
|
|
"os"
|
|
"strings"
|
|
"testing"
|
|
"time"
|
|
|
|
"gotest.tools/v3/assert"
|
|
)
|
|
|
|
func TestBuildLogsURL(t *testing.T) {
|
|
tests := []struct {
|
|
name string
|
|
appID string
|
|
want string
|
|
}{
|
|
{
|
|
name: "empty app id yields paramless url",
|
|
appID: "",
|
|
want: "docker-desktop://dashboard/logs",
|
|
},
|
|
{
|
|
name: "simple project name",
|
|
appID: "myapp",
|
|
want: "docker-desktop://dashboard/logs?appId=myapp",
|
|
},
|
|
{
|
|
name: "name with hyphen and digits is preserved",
|
|
appID: "my-app-2",
|
|
want: "docker-desktop://dashboard/logs?appId=my-app-2",
|
|
},
|
|
{
|
|
name: "characters that need percent-encoding are escaped",
|
|
appID: "weird name/with spaces",
|
|
want: "docker-desktop://dashboard/logs?appId=weird+name%2Fwith+spaces",
|
|
},
|
|
}
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
assert.Equal(t, BuildLogsURL(tt.appID), tt.want)
|
|
})
|
|
}
|
|
}
|
|
|
|
func TestBuildLogsURL_TruncatesLongAppID(t *testing.T) {
|
|
long := strings.Repeat("a", LogsAppIDMaxLen+50)
|
|
got := BuildLogsURL(long)
|
|
want := "docker-desktop://dashboard/logs?appId=" + strings.Repeat("a", LogsAppIDMaxLen)
|
|
assert.Equal(t, got, want)
|
|
}
|
|
|
|
func TestClientPing(t *testing.T) {
|
|
if testing.Short() {
|
|
t.Skip("Skipped in short mode - test connects to Docker Desktop")
|
|
}
|
|
desktopEndpoint := os.Getenv("COMPOSE_TEST_DESKTOP_ENDPOINT")
|
|
if desktopEndpoint == "" {
|
|
t.Skip("Skipping - COMPOSE_TEST_DESKTOP_ENDPOINT not defined")
|
|
}
|
|
|
|
client := NewClient(desktopEndpoint)
|
|
t.Cleanup(func() {
|
|
_ = client.Close()
|
|
})
|
|
|
|
now := time.Now()
|
|
|
|
ret, err := client.Ping(t.Context())
|
|
assert.NilError(t, err)
|
|
|
|
serverTime := time.Unix(0, ret.ServerTime)
|
|
assert.Assert(t, now.Before(serverTime))
|
|
}
|