| 1 |
package packet |
| 2 |
|
| 3 |
import ( |
| 4 |
"bytes" |
| 5 |
"testing" |
| 6 |
) |
| 7 |
|
| 8 |
func TestNotationGetData(t *testing.T) { |
| 9 |
notation := Notation{ |
| 10 |
Name: "[email protected]", |
| 11 |
Value: []byte("test-value"), |
| 12 |
IsCritical: true, |
| 13 |
IsHumanReadable: true, |
| 14 |
} |
| 15 |
expected := []byte{0x80, 0, 0, 0, 0, 14, 0, 10} |
| 16 |
expected = append(expected, []byte(notation.Name)...) |
| 17 |
expected = append(expected, []byte(notation.Value)...) |
| 18 |
data := notation.getData() |
| 19 |
if !bytes.Equal(expected, data) { |
| 20 |
t.Fatalf("Expected %s, got %s", expected, data) |
| 21 |
} |
| 22 |
} |
| 23 |
|
| 24 |
func TestNotationGetDataNotHumanReadable(t *testing.T) { |
| 25 |
notation := Notation{ |
| 26 |
Name: "[email protected]", |
| 27 |
Value: []byte("test-value"), |
| 28 |
IsCritical: true, |
| 29 |
IsHumanReadable: false, |
| 30 |
} |
| 31 |
expected := []byte{0, 0, 0, 0, 0, 14, 0, 10} |
| 32 |
expected = append(expected, []byte(notation.Name)...) |
| 33 |
expected = append(expected, []byte(notation.Value)...) |
| 34 |
data := notation.getData() |
| 35 |
if !bytes.Equal(expected, data) { |
| 36 |
t.Fatalf("Expected %s, got %s", expected, data) |
| 37 |
} |
| 38 |
} |