diff --git a/lib/supermon/supermon.go b/lib/supermon/supermon.go index 74a20bf..102fce9 100644 --- a/lib/supermon/supermon.go +++ b/lib/supermon/supermon.go @@ -317,6 +317,7 @@ func (o operator) GetFile(filename string) (disk.FileInfo, error) { Sectors: len(data) / 256, Length: len(data), Locked: false, + Type: disk.FiletypeBinary, } return disk.FileInfo{ Descriptor: desc, diff --git a/lib/supermon/supermon_test.go b/lib/supermon/supermon_test.go index 6dde6b7..2c8ac15 100644 --- a/lib/supermon/supermon_test.go +++ b/lib/supermon/supermon_test.go @@ -8,6 +8,8 @@ import ( "github.com/zellyn/diskii/lib/disk" ) +const testDisk = "testdata/chacha20.dsk" + // loadSectorMap loads a sector map for the disk image contained in // filename. It returns the sector map and a sector disk. func loadSectorMap(filename string) (SectorMap, disk.SectorDisk, error) { @@ -25,7 +27,7 @@ func loadSectorMap(filename string) (SectorMap, disk.SectorDisk, error) { // TestReadSectorMap tests the reading of the sector map of a test // disk. func TestReadSectorMap(t *testing.T) { - sm, _, err := loadSectorMap("testdata/chacha20.dsk") + sm, _, err := loadSectorMap(testDisk) if err != nil { t.Fatal(err) } @@ -62,7 +64,7 @@ func TestReadSectorMap(t *testing.T) { // TestReadSymbolTable tests the reading of the symbol table of a test // disk. func TestReadSymbolTable(t *testing.T) { - sm, sd, err := loadSectorMap("testdata/chacha20.dsk") + sm, sd, err := loadSectorMap(testDisk) if err != nil { t.Fatal(err) } @@ -105,3 +107,33 @@ func TestReadSymbolTable(t *testing.T) { } } } + +// TestGetFile tests the retrieval of a file's contents, using the +// Operator interface. +func TestGetFile(t *testing.T) { + sd, err := disk.Open(testDisk) + if err != nil { + t.Fatal(err) + } + op, err := disk.OperatorFor(sd) + if err != nil { + t.Fatal(err) + } + file, err := op.GetFile("FTOBE") + if err != nil { + t.Fatal(err) + } + got := string(file.Data) + // The extra newline pads us to 256 bytes… + want := `To be, or not to be, that is the question: +Whether 'tis Nobler in the mind to suffer +The Slings and Arrows of outrageous Fortune, +Or to take Arms against a Sea of troubles, +And by opposing end them: to die, to sleep +No more; and by a sleep, to say we end + +` + if got != want { + t.Errorf("Incorrect result for GetFile(\"TOBE\"): want %q; got %q", want, got) + } +}