1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114
|
package bsdp
import (
"testing"
"github.com/stretchr/testify/require"
)
func TestOptBootImageListInterfaceMethods(t *testing.T) {
bs := []BootImage{
BootImage{
ID: BootImageID{
IsInstall: false,
ImageType: BootImageTypeMacOSX,
Index: 1001,
},
Name: "bsdp-1",
},
BootImage{
ID: BootImageID{
IsInstall: true,
ImageType: BootImageTypeMacOS9,
Index: 9009,
},
Name: "bsdp-2",
},
}
o := OptBootImageList(bs...)
require.Equal(t, OptionBootImageList, o.Code, "Code")
expectedBytes := []byte{
// boot image 1
0x1, 0x0, 0x03, 0xe9, // ID
6, // name length
'b', 's', 'd', 'p', '-', '1',
// boot image 1
0x80, 0x0, 0x23, 0x31, // ID
6, // name length
'b', 's', 'd', 'p', '-', '2',
}
require.Equal(t, expectedBytes, o.Value.ToBytes(), "ToBytes")
}
func TestParseOptBootImageList(t *testing.T) {
data := []byte{
// boot image 1
0x1, 0x0, 0x03, 0xe9, // ID
6, // name length
'b', 's', 'd', 'p', '-', '1',
// boot image 1
0x80, 0x0, 0x23, 0x31, // ID
6, // name length
'b', 's', 'd', 'p', '-', '2',
}
var o BootImageList
err := o.FromBytes(data)
require.NoError(t, err)
expectedBootImages := BootImageList{
BootImage{
ID: BootImageID{
IsInstall: false,
ImageType: BootImageTypeMacOSX,
Index: 1001,
},
Name: "bsdp-1",
},
BootImage{
ID: BootImageID{
IsInstall: true,
ImageType: BootImageTypeMacOS9,
Index: 9009,
},
Name: "bsdp-2",
},
}
require.Equal(t, expectedBootImages, o)
// Error parsing boot image (malformed)
data = []byte{
// boot image 1
0x1, 0x0, 0x03, 0xe9, // ID
4, // name length
'b', 's', 'd', 'p', '-', '1',
// boot image 2
0x80, 0x0, 0x23, 0x31, // ID
6, // name length
'b', 's', 'd', 'p', '-', '2',
}
err = o.FromBytes(data)
require.Error(t, err, "should get error from bad boot image")
}
func TestOptBootImageListString(t *testing.T) {
bs := []BootImage{
BootImage{
ID: BootImageID{
IsInstall: false,
ImageType: BootImageTypeMacOSX,
Index: 1001,
},
Name: "bsdp-1",
},
BootImage{
ID: BootImageID{
IsInstall: true,
ImageType: BootImageTypeMacOS9,
Index: 9009,
},
Name: "bsdp-2",
},
}
o := OptBootImageList(bs...)
expectedString := "BSDP Boot Image List: bsdp-1 [1001] uninstallable macOS image, bsdp-2 [9009] installable macOS 9 image"
require.Equal(t, expectedString, o.String())
}
|