Skip to content

Commit d91df19

Browse files
aledbfclaude
andcommitted
test: hold three edits the CI mutation sample found unrefused
The pull request's mutate job, on the docker8 fleet, left three edits no unit test refused: isTerminalWriter's file-mode check (only a buffer was tried), singleContainerRemoteUserUID with an image inspection that has no Config, and win32's ${localWorkspaceFolderBasename}. A local run refused them only through Docker-backed tests the job does not reach. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 parent 11cd4d0 commit d91df19

3 files changed

Lines changed: 80 additions & 0 deletions

File tree

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package cli
2+
3+
import (
4+
"os"
5+
"path/filepath"
6+
"testing"
7+
)
8+
9+
// A character device, as a terminal is, counts as a terminal writer; a regular
10+
// file does not.
11+
func TestIsTerminalWriterChecksTheFileMode(t *testing.T) {
12+
devNull, err := os.OpenFile(os.DevNull, os.O_WRONLY, 0)
13+
if err != nil {
14+
t.Fatal(err)
15+
}
16+
defer devNull.Close()
17+
if !isTerminalWriter(devNull) {
18+
t.Errorf("%s is a character device: want a terminal writer", os.DevNull)
19+
}
20+
regular, err := os.Create(filepath.Join(t.TempDir(), "out"))
21+
if err != nil {
22+
t.Fatal(err)
23+
}
24+
defer regular.Close()
25+
if isTerminalWriter(regular) {
26+
t.Error("a regular file is not a terminal writer")
27+
}
28+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
package cli
2+
3+
import (
4+
"io"
5+
"testing"
6+
7+
"github.com/devcontainers/cli/internal/config"
8+
"github.com/devcontainers/cli/internal/docker"
9+
"github.com/devcontainers/cli/internal/log"
10+
)
11+
12+
// An image whose inspection has no Config carries no metadata: the UID update
13+
// reads none and, with updates off, keeps the image.
14+
func TestSingleContainerRemoteUserUIDImageWithoutConfig(t *testing.T) {
15+
logger := log.New(log.Options{Writer: io.Discard})
16+
engine := &fakeEngineAPI{images: map[string]string{"img:1": `{}`}}
17+
r := &upRunner{
18+
log: logger,
19+
engine: &docker.EngineClient{API: engine, Log: logger},
20+
opts: &upOpts{updateRemoteUserUIDDefault: "off"},
21+
}
22+
got, err := r.singleContainerRemoteUserUID(t.Context(), "img:1", &config.DevContainer{}, t.TempDir())
23+
if err != nil {
24+
t.Fatal(err)
25+
}
26+
if got != "img:1" {
27+
t.Errorf("image = %q, want img:1 kept", got)
28+
}
29+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package config
2+
3+
import "testing"
4+
5+
// On win32 both '\' and '/' separate the workspace folder's basename, and a
6+
// folder without one is its own basename.
7+
func TestLocalWorkspaceFolderBasenameOnWindows(t *testing.T) {
8+
for folder, want := range map[string]string{
9+
`C:\Users\me\project`: "project",
10+
`C:/Users/me/project`: "project",
11+
`C:\Users/me\mixed`: "mixed",
12+
`project`: "project",
13+
} {
14+
ctx := HostSubContext{Platform: "win32", LocalWorkspaceFolder: folder, Env: map[string]string{}}
15+
got, err := NewVariableResolver().Resolve(SubstitutionContext{HostSubContext: ctx}, PhaseHost, "${localWorkspaceFolderBasename}")
16+
if err != nil {
17+
t.Fatal(err)
18+
}
19+
if got != want {
20+
t.Errorf("basename of %q = %v, want %q", folder, got, want)
21+
}
22+
}
23+
}

0 commit comments

Comments
 (0)