跳到主要内容

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

浏览文件

init_packets_test.go

114 行 · 2.6 KB历史下载
1package sshfx
2
3import (
4 "bytes"
5 "testing"
6)
7
8func TestInitPacket(t *testing.T) {
9 var version uint8 = 3
10
11 p := &InitPacket{
12 Version: uint32(version),
13 Extensions: []*ExtensionPair{
14 {
15 Name: "foo",
16 Data: "1",
17 },
18 },
19 }
20
21 buf, err := p.MarshalBinary()
22 if err != nil {
23 t.Fatal("unexpected error:", err)
24 }
25
26 want := []byte{
27 0x00, 0x00, 0x00, 17,
28 1,
29 0x00, 0x00, 0x00, version,
30 0x00, 0x00, 0x00, 3, 'f', 'o', 'o',
31 0x00, 0x00, 0x00, 1, '1',
32 }
33
34 if !bytes.Equal(buf, want) {
35 t.Fatalf("MarshalBinary() = %X, but wanted %X", buf, want)
36 }
37
38 *p = InitPacket{}
39
40 // UnmarshalBinary assumes the uint32(length) + uint8(type) have already been consumed.
41 if err := p.UnmarshalBinary(buf[5:]); err != nil {
42 t.Fatal("unexpected error:", err)
43 }
44
45 if p.Version != uint32(version) {
46 t.Errorf("UnmarshalBinary(): Version was %d, but expected %d", p.Version, version)
47 }
48
49 if len(p.Extensions) != 1 {
50 t.Fatalf("UnmarshalBinary(): len(p.Extensions) was %d, but expected %d", len(p.Extensions), 1)
51 }
52
53 if got, want := p.Extensions[0].Name, "foo"; got != want {
54 t.Errorf("UnmarshalBinary(): p.Extensions[0].Name was %q, but expected %q", got, want)
55 }
56
57 if got, want := p.Extensions[0].Data, "1"; got != want {
58 t.Errorf("UnmarshalBinary(): p.Extensions[0].Data was %q, but expected %q", got, want)
59 }
60}
61
62func TestVersionPacket(t *testing.T) {
63 var version uint8 = 3
64
65 p := &VersionPacket{
66 Version: uint32(version),
67 Extensions: []*ExtensionPair{
68 {
69 Name: "foo",
70 Data: "1",
71 },
72 },
73 }
74
75 buf, err := p.MarshalBinary()
76 if err != nil {
77 t.Fatal("unexpected error:", err)
78 }
79
80 want := []byte{
81 0x00, 0x00, 0x00, 17,
82 2,
83 0x00, 0x00, 0x00, version,
84 0x00, 0x00, 0x00, 3, 'f', 'o', 'o',
85 0x00, 0x00, 0x00, 1, '1',
86 }
87
88 if !bytes.Equal(buf, want) {
89 t.Fatalf("MarshalBinary() = %X, but wanted %X", buf, want)
90 }
91
92 *p = VersionPacket{}
93
94 // UnmarshalBinary assumes the uint32(length) + uint8(type) have already been consumed.
95 if err := p.UnmarshalBinary(buf[5:]); err != nil {
96 t.Fatal("unexpected error:", err)
97 }
98
99 if p.Version != uint32(version) {
100 t.Errorf("UnmarshalBinary(): Version was %d, but expected %d", p.Version, version)
101 }
102
103 if len(p.Extensions) != 1 {
104 t.Fatalf("UnmarshalBinary(): len(p.Extensions) was %d, but expected %d", len(p.Extensions), 1)
105 }
106
107 if got, want := p.Extensions[0].Name, "foo"; got != want {
108 t.Errorf("UnmarshalBinary(): p.Extensions[0].Name was %q, but expected %q", got, want)
109 }
110
111 if got, want := p.Extensions[0].Data, "1"; got != want {
112 t.Errorf("UnmarshalBinary(): p.Extensions[0].Data was %q, but expected %q", got, want)
113 }
114}