跳到主要内容

Claude Cage · 面向 Claude 的隔离开发环境,支持桌面工作台、多账号、远程部署与移动端连接。上游 Lee-xeo/Claude-Cage 完整源码镜像,非灵栈原创;主许可 MIT,第三方组件遵循各自许可。来源:https://github.com/Lee-xeo/Claude-Cage 。手动同步,不附带 Release 安装包。

浏览文件

hardlink_test.go

69 行 · 1.7 KB历史下载
1package openssh
2
3import (
4 "bytes"
5 "testing"
6
7 sshfx "github.com/pkg/sftp/internal/encoding/ssh/filexfer"
8)
9
10var _ sshfx.PacketMarshaller = &HardlinkExtendedPacket{}
11
12func init() {
13 RegisterExtensionHardlink()
14}
15
16func TestHardlinkExtendedPacket(t *testing.T) {
17 const (
18 id = 42
19 oldpath = "/foo"
20 newpath = "/bar"
21 )
22
23 ep := &HardlinkExtendedPacket{
24 OldPath: oldpath,
25 NewPath: newpath,
26 }
27
28 data, err := sshfx.ComposePacket(ep.MarshalPacket(id, nil))
29 if err != nil {
30 t.Fatal("unexpected error:", err)
31 }
32
33 want := []byte{
34 0x00, 0x00, 0x00, 45,
35 200,
36 0x00, 0x00, 0x00, 42,
37 0x00, 0x00, 0x00, 20, 'h', 'a', 'r', 'd', 'l', 'i', 'n', 'k', '@', 'o', 'p', 'e', 'n', 's', 's', 'h', '.', 'c', 'o', 'm',
38 0x00, 0x00, 0x00, 4, '/', 'f', 'o', 'o',
39 0x00, 0x00, 0x00, 4, '/', 'b', 'a', 'r',
40 }
41
42 if !bytes.Equal(data, want) {
43 t.Fatalf("MarshalPacket() = %X, but wanted %X", data, want)
44 }
45
46 var p sshfx.ExtendedPacket
47
48 // UnmarshalPacketBody assumes the (length, type, request-id) have already been consumed.
49 if err := p.UnmarshalPacketBody(sshfx.NewBuffer(data[9:])); err != nil {
50 t.Fatal("unexpected error:", err)
51 }
52
53 if p.ExtendedRequest != extensionHardlink {
54 t.Errorf("UnmarshalPacketBody(): ExtendedRequest was %q, but expected %q", p.ExtendedRequest, extensionHardlink)
55 }
56
57 ep, ok := p.Data.(*HardlinkExtendedPacket)
58 if !ok {
59 t.Fatalf("UnmarshaledPacketBody(): Data was type %T, but expected *HardlinkExtendedPacket", p.Data)
60 }
61
62 if ep.OldPath != oldpath {
63 t.Errorf("UnmarshalPacketBody(): OldPath was %q, but expected %q", ep.OldPath, oldpath)
64 }
65
66 if ep.NewPath != newpath {
67 t.Errorf("UnmarshalPacketBody(): NewPath was %q, but expected %q", ep.NewPath, newpath)
68 }
69}