-
Notifications
You must be signed in to change notification settings - Fork 207
Expand file tree
/
Copy pathreparse_lx_test.go
More file actions
152 lines (128 loc) · 3.51 KB
/
reparse_lx_test.go
File metadata and controls
152 lines (128 loc) · 3.51 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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
//go:build windows
package winio
import (
"testing"
)
const (
testLxSymlinkAbsolutePath = "/usr/bin/bash"
testWindowsSymlinkPath = `C:\Windows\System32`
testLxSymlinkRelativePath = "../bin/sh"
testLxSymlinkSpecialCharsPath = "/path/with spaces/and-special!@#$%/файл.txt"
)
func TestLxSymlinkRoundTrip(t *testing.T) {
// Test LX symlink encode/decode
original := &ReparsePoint{
Target: testLxSymlinkAbsolutePath,
IsMountPoint: false,
IsLxSymlink: true,
}
// Encode
encoded := EncodeReparsePoint(original)
// Decode
decoded, err := DecodeReparsePoint(encoded)
if err != nil {
t.Fatalf("Failed to decode: %v", err)
}
// Verify
if decoded.Target != original.Target {
t.Errorf("Target mismatch: got %q, want %q", decoded.Target, original.Target)
}
if decoded.IsLxSymlink != original.IsLxSymlink {
t.Errorf("IsLxSymlink mismatch: got %v, want %v", decoded.IsLxSymlink, original.IsLxSymlink)
}
if decoded.IsMountPoint != original.IsMountPoint {
t.Errorf("IsMountPoint mismatch: got %v, want %v", decoded.IsMountPoint, original.IsMountPoint)
}
}
func TestWindowsSymlinkNotLx(t *testing.T) {
// Test that regular Windows symlinks are not marked as LX
original := &ReparsePoint{
Target: testWindowsSymlinkPath,
IsMountPoint: false,
IsLxSymlink: false,
}
// Encode
encoded := EncodeReparsePoint(original)
// Decode
decoded, err := DecodeReparsePoint(encoded)
if err != nil {
t.Fatalf("Failed to decode: %v", err)
}
// Verify it's NOT an LX symlink
if decoded.IsLxSymlink {
t.Errorf("Windows symlink incorrectly marked as LX symlink")
}
}
func TestLxSymlinkEmptyTarget(t *testing.T) {
// Test LX symlink with empty target
original := &ReparsePoint{
Target: "",
IsMountPoint: false,
IsLxSymlink: true,
}
// Encode
encoded := EncodeReparsePoint(original)
// Decode
decoded, err := DecodeReparsePoint(encoded)
if err != nil {
t.Fatalf("Failed to decode: %v", err)
}
// Verify
if decoded.Target != original.Target {
t.Errorf("Target mismatch: got %q, want %q", decoded.Target, original.Target)
}
if !decoded.IsLxSymlink {
t.Errorf("IsLxSymlink should be true")
}
}
func TestLxSymlinkRelativePath(t *testing.T) {
// Test LX symlink with relative path
original := &ReparsePoint{
Target: testLxSymlinkRelativePath,
IsMountPoint: false,
IsLxSymlink: true,
}
// Encode
encoded := EncodeReparsePoint(original)
// Decode
decoded, err := DecodeReparsePoint(encoded)
if err != nil {
t.Fatalf("Failed to decode: %v", err)
}
// Verify
if decoded.Target != original.Target {
t.Errorf("Target mismatch: got %q, want %q", decoded.Target, original.Target)
}
if !decoded.IsLxSymlink {
t.Errorf("IsLxSymlink should be true")
}
}
func TestLxSymlinkSpecialCharacters(t *testing.T) {
// Test LX symlink with special characters and Unicode
original := &ReparsePoint{
Target: testLxSymlinkSpecialCharsPath,
IsMountPoint: false,
IsLxSymlink: true,
}
// Encode
encoded := EncodeReparsePoint(original)
// Decode
decoded, err := DecodeReparsePoint(encoded)
if err != nil {
t.Fatalf("Failed to decode: %v", err)
}
// Verify
if decoded.Target != original.Target {
t.Errorf("Target mismatch: got %q, want %q", decoded.Target, original.Target)
}
if !decoded.IsLxSymlink {
t.Errorf("IsLxSymlink should be true")
}
}
func TestEncodeReparsePointNil(t *testing.T) {
// Test encoding a nil ReparsePoint
encoded := EncodeReparsePoint(nil)
if encoded != nil {
t.Errorf("Expected nil result for nil input, got %v", encoded)
}
}