Skip to content

Commit 11cd4d0

Browse files
aledbfclaude
andcommitted
test(cli): hold the mount metadata's type default and empty specs
go tool mutate over the pull request's diff left two edits in mounts.go no test refused: an object mount's explicit type versus the bind default, and an empty string mount being dropped from the metadata entry. Both are now asserted. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 parent 50e7b9f commit 11cd4d0

1 file changed

Lines changed: 37 additions & 1 deletion

File tree

‎internal/cli/mounts_held_test.go‎

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
package cli
22

3-
import "testing"
3+
import (
4+
"encoding/json"
5+
"testing"
6+
7+
"github.com/devcontainers/cli/internal/config"
8+
)
49

510
// A string mount from image metadata resolves ${devcontainerId} across the
611
// whole spec before it is parsed.
@@ -13,3 +18,34 @@ func TestMountFromMetadataStringSpec(t *testing.T) {
1318
t.Errorf("mount = %+v, want volume cache-abc123 -> /cache", m)
1419
}
1520
}
21+
22+
// An object mount keeps the type it names and is a bind mount without one.
23+
func TestMountFromMetadataObjectType(t *testing.T) {
24+
volume, err := mountFromMetadata(map[string]any{"type": "volume", "source": "v", "target": "/v"}, "id")
25+
if err != nil {
26+
t.Fatal(err)
27+
}
28+
if string(volume.Type) != "volume" {
29+
t.Errorf("type = %q, want volume", volume.Type)
30+
}
31+
bind, err := mountFromMetadata(map[string]any{"source": "/h", "target": "/c"}, "id")
32+
if err != nil {
33+
t.Fatal(err)
34+
}
35+
if string(bind.Type) != "bind" {
36+
t.Errorf("type = %q, want bind when the mount names none", bind.Type)
37+
}
38+
}
39+
40+
// An empty string mount records nothing in the configuration's metadata entry;
41+
// a non-empty one is kept as written.
42+
func TestMetadataMountsSkipsEmptyStrings(t *testing.T) {
43+
var cfg config.DevContainer
44+
if err := json.Unmarshal([]byte(`{"mounts": ["", "source=/h,target=/c,type=bind"]}`), &cfg); err != nil {
45+
t.Fatal(err)
46+
}
47+
got := metadataMounts(&cfg)
48+
if len(got) != 1 || got[0] != "source=/h,target=/c,type=bind" {
49+
t.Errorf("metadataMounts = %#v, want only the non-empty spec", got)
50+
}
51+
}

0 commit comments

Comments
 (0)