39 lines
813 B
Go
39 lines
813 B
Go
|
|
package packed
|
||
|
|
|
||
|
|
import (
|
||
|
|
"bytes"
|
||
|
|
"os"
|
||
|
|
"testing"
|
||
|
|
)
|
||
|
|
|
||
|
|
func TestMapAndLoad(t *testing.T) {
|
||
|
|
rawPack, err := os.ReadFile("testdata/helloworld.pack")
|
||
|
|
if err != nil {
|
||
|
|
t.Fatal(err)
|
||
|
|
}
|
||
|
|
rawText, err := os.ReadFile("testdata/helloworld.txt")
|
||
|
|
if err != nil {
|
||
|
|
t.Fatal(err)
|
||
|
|
}
|
||
|
|
|
||
|
|
mapped, err := MapAndLoad("testdata/helloworld.pack")
|
||
|
|
if err != nil {
|
||
|
|
t.Fatal(err)
|
||
|
|
}
|
||
|
|
defer mapped.Close()
|
||
|
|
|
||
|
|
if !bytes.Equal(mapped.Data, rawPack) {
|
||
|
|
t.Error("mapped data does not match raw file")
|
||
|
|
}
|
||
|
|
|
||
|
|
file := mapped.Directory.Files["/helloworld.txt"]
|
||
|
|
if file == nil {
|
||
|
|
t.Fatal("directory does not contain /helloworld.txt")
|
||
|
|
}
|
||
|
|
|
||
|
|
start := file.Uncompressed.Offset
|
||
|
|
end := start + file.Uncompressed.Length
|
||
|
|
if !bytes.Equal(rawText, mapped.Data[start:end]) {
|
||
|
|
t.Error("uncompressed file does not match testdata/helloworld.txt")
|
||
|
|
}
|
||
|
|
}
|