| 1 | package sshfx |
| 2 | |
| 3 | import ( |
| 4 | "bytes" |
| 5 | "testing" |
| 6 | ) |
| 7 | |
| 8 | func TestExtensionPair(t *testing.T) { |
| 9 | const ( |
| 10 | name = "foo" |
| 11 | data = "1" |
| 12 | ) |
| 13 | |
| 14 | pair := &ExtensionPair{ |
| 15 | Name: name, |
| 16 | Data: data, |
| 17 | } |
| 18 | |
| 19 | buf, err := pair.MarshalBinary() |
| 20 | if err != nil { |
| 21 | t.Fatal("unexpected error:", err) |
| 22 | } |
| 23 | |
| 24 | want := []byte{ |
| 25 | 0x00, 0x00, 0x00, 3, |
| 26 | 'f', 'o', 'o', |
| 27 | 0x00, 0x00, 0x00, 1, |
| 28 | '1', |
| 29 | } |
| 30 | |
| 31 | if !bytes.Equal(buf, want) { |
| 32 | t.Errorf("ExtensionPair.MarshalBinary() = %X, but wanted %X", buf, want) |
| 33 | } |
| 34 | |
| 35 | *pair = ExtensionPair{} |
| 36 | |
| 37 | if err := pair.UnmarshalBinary(buf); err != nil { |
| 38 | t.Fatal("unexpected error:", err) |
| 39 | } |
| 40 | |
| 41 | if pair.Name != name { |
| 42 | t.Errorf("ExtensionPair.UnmarshalBinary(): Name was %q, but expected %q", pair.Name, name) |
| 43 | } |
| 44 | |
| 45 | if pair.Data != data { |
| 46 | t.Errorf("RawPacket.UnmarshalBinary(): Data was %q, but expected %q", pair.Data, data) |
| 47 | } |
| 48 | |
| 49 | } |