-
Notifications
You must be signed in to change notification settings - Fork 543
Expand file tree
/
Copy pathreproduce_issue_test.go
More file actions
81 lines (71 loc) · 2.1 KB
/
reproduce_issue_test.go
File metadata and controls
81 lines (71 loc) · 2.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
package setup
import (
"os"
"os/user"
"path/filepath"
"testing"
"github.com/loft-sh/devpod/pkg/devcontainer/config"
"github.com/loft-sh/log"
)
func TestChownMounts(t *testing.T) {
// Create temp directories for mounts
tempDir := t.TempDir()
mountTarget1 := filepath.Join(tempDir, "mount1")
mountTarget2 := filepath.Join(tempDir, "mount2")
err := os.Mkdir(mountTarget1, 0755)
if err != nil {
t.Fatalf("Failed to create temp dir mount1: %v", err)
}
err = os.Mkdir(mountTarget2, 0755)
if err != nil {
t.Fatalf("Failed to create temp dir mount2: %v", err)
}
// Set MarkerBaseDir to temp dir to avoid permission issues
oldMarkerBaseDir := MarkerBaseDir
MarkerBaseDir = t.TempDir()
defer func() { MarkerBaseDir = oldMarkerBaseDir }()
// Get current user
currentUser, err := user.Current()
if err != nil {
t.Fatalf("Failed to get current user: %v", err)
}
// Create a mock result with bind mounts
result := &config.Result{
MergedConfig: &config.MergedDevContainerConfig{
DevContainerConfigBase: config.DevContainerConfigBase{
RemoteUser: currentUser.Username,
},
NonComposeBase: config.NonComposeBase{
Mounts: []*config.Mount{
{
Source: "/local/path",
Target: mountTarget1,
Type: "bind",
},
},
},
},
SubstitutionContext: &config.SubstitutionContext{
WorkspaceMount: "source=/ws/src,target=" + mountTarget2 + ",type=bind",
ContainerWorkspaceFolder: mountTarget2,
},
}
// Mock logger
logger := log.Discard
// Call ChownMounts
// We expect it to succeed for the existing directories with current user
err = ChownMounts(result, logger)
if err != nil {
t.Errorf("ChownMounts failed: %v", err)
}
// Verify marker file created
markerPath := filepath.Join(MarkerBaseDir, "chownMounts.marker")
if _, err := os.Stat(markerPath); os.IsNotExist(err) {
t.Errorf("Marker file not created at %s", markerPath)
}
// Call again, should be skipped (log logic inside, but we rely on function returning nil and not erroring)
err = ChownMounts(result, logger)
if err != nil {
t.Errorf("ChownMounts second call failed: %v", err)
}
}