| 
									
										
										
										
											2023-03-28 01:05:24 +08:00
										 |  |  | package sshfx | 
					
						
							| 
									
										
										
										
											2021-03-19 01:02:43 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | import ( | 
					
						
							|  |  |  | 	"bytes" | 
					
						
							|  |  |  | 	"testing" | 
					
						
							|  |  |  | ) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | func TestExtensionPair(t *testing.T) { | 
					
						
							|  |  |  | 	const ( | 
					
						
							|  |  |  | 		name = "foo" | 
					
						
							|  |  |  | 		data = "1" | 
					
						
							|  |  |  | 	) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	pair := &ExtensionPair{ | 
					
						
							|  |  |  | 		Name: name, | 
					
						
							|  |  |  | 		Data: data, | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-05-22 23:00:04 +08:00
										 |  |  | 	buf, err := pair.MarshalBinary() | 
					
						
							|  |  |  | 	if err != nil { | 
					
						
							|  |  |  | 		t.Fatal("unexpected error:", err) | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2021-03-19 01:02:43 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	want := []byte{ | 
					
						
							|  |  |  | 		0x00, 0x00, 0x00, 3, | 
					
						
							|  |  |  | 		'f', 'o', 'o', | 
					
						
							|  |  |  | 		0x00, 0x00, 0x00, 1, | 
					
						
							|  |  |  | 		'1', | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-05-22 23:00:04 +08:00
										 |  |  | 	if !bytes.Equal(buf, want) { | 
					
						
							|  |  |  | 		t.Errorf("ExtensionPair.MarshalBinary() = %X, but wanted %X", buf, want) | 
					
						
							| 
									
										
										
										
											2021-03-19 01:02:43 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	*pair = ExtensionPair{} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-05-22 23:00:04 +08:00
										 |  |  | 	if err := pair.UnmarshalBinary(buf); err != nil { | 
					
						
							| 
									
										
										
										
											2021-03-19 01:02:43 +08:00
										 |  |  | 		t.Fatal("unexpected error:", err) | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if pair.Name != name { | 
					
						
							| 
									
										
										
										
											2021-05-22 23:00:04 +08:00
										 |  |  | 		t.Errorf("ExtensionPair.UnmarshalBinary(): Name was %q, but expected %q", pair.Name, name) | 
					
						
							| 
									
										
										
										
											2021-03-19 01:02:43 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if pair.Data != data { | 
					
						
							|  |  |  | 		t.Errorf("RawPacket.UnmarshalBinary(): Data was %q, but expected %q", pair.Data, data) | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | } |