Fix paths asset regression
This commit is contained in:
@@ -175,6 +175,173 @@ func TestExtractReadsHAKAssets(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestExtractRefusesAssetsWhenAssetsPathIsUnset(t *testing.T) {
|
||||
root := t.TempDir()
|
||||
t.Chdir(root)
|
||||
mustMkdir(t, filepath.Join(root, "src"))
|
||||
mustMkdir(t, filepath.Join(root, "build"))
|
||||
mustWriteFile(t, filepath.Join(root, "root_level_asset.mdl"), "must stay")
|
||||
|
||||
mustWriteFile(t, filepath.Join(root, "nwn-tool.yaml"), `
|
||||
module:
|
||||
name: Test Module
|
||||
resref: testmod
|
||||
paths:
|
||||
source: src
|
||||
build: build
|
||||
`)
|
||||
|
||||
p, err := project.Load(root)
|
||||
if err != nil {
|
||||
t.Fatalf("load project: %v", err)
|
||||
}
|
||||
if err := p.Scan(); err != nil {
|
||||
t.Fatalf("scan: %v", err)
|
||||
}
|
||||
if len(p.Inventory.AssetFiles) != 0 {
|
||||
t.Fatalf("expected unset assets path not to inventory repository-root assets, got %#v", p.Inventory.AssetFiles)
|
||||
}
|
||||
|
||||
modFile, err := os.Create(p.ModuleArchivePath())
|
||||
if err != nil {
|
||||
t.Fatalf("create mod: %v", err)
|
||||
}
|
||||
if err := erf.Write(modFile, erf.New("MOD ", nil)); err != nil {
|
||||
t.Fatalf("write mod: %v", err)
|
||||
}
|
||||
if err := modFile.Close(); err != nil {
|
||||
t.Fatalf("close mod: %v", err)
|
||||
}
|
||||
|
||||
hakFile, err := os.Create(filepath.Join(root, "build", "vfx.hak"))
|
||||
if err != nil {
|
||||
t.Fatalf("create hak: %v", err)
|
||||
}
|
||||
if err := erf.Write(hakFile, erf.New("HAK ", []erf.Resource{
|
||||
{Name: "test_vfx", Type: 0x07D2, Data: []byte("mdl-data")},
|
||||
})); err != nil {
|
||||
t.Fatalf("write hak: %v", err)
|
||||
}
|
||||
if err := hakFile.Close(); err != nil {
|
||||
t.Fatalf("close hak: %v", err)
|
||||
}
|
||||
|
||||
_, err = Extract(p)
|
||||
if err == nil {
|
||||
t.Fatal("expected extract to fail")
|
||||
}
|
||||
if !strings.Contains(err.Error(), "paths.assets is not configured") {
|
||||
t.Fatalf("expected missing assets path error, got %v", err)
|
||||
}
|
||||
if _, statErr := os.Stat(filepath.Join(root, "mdl", "test_vfx.mdl")); !os.IsNotExist(statErr) {
|
||||
t.Fatalf("expected no root-level extracted asset, stat err=%v", statErr)
|
||||
}
|
||||
if _, statErr := os.Stat(filepath.Join(root, "root_level_asset.mdl")); statErr != nil {
|
||||
t.Fatalf("expected pre-existing root-level asset to remain, stat err=%v", statErr)
|
||||
}
|
||||
}
|
||||
|
||||
func TestExtractRefusesAssetsWhenAssetsPathIsRepositoryRoot(t *testing.T) {
|
||||
root := t.TempDir()
|
||||
mustMkdir(t, filepath.Join(root, "src"))
|
||||
mustMkdir(t, filepath.Join(root, "build"))
|
||||
|
||||
mustWriteFile(t, filepath.Join(root, "nwn-tool.yaml"), `
|
||||
module:
|
||||
name: Test Module
|
||||
resref: testmod
|
||||
paths:
|
||||
source: src
|
||||
assets: .
|
||||
build: build
|
||||
`)
|
||||
|
||||
p, err := project.Load(root)
|
||||
if err != nil {
|
||||
t.Fatalf("load project: %v", err)
|
||||
}
|
||||
|
||||
modFile, err := os.Create(p.ModuleArchivePath())
|
||||
if err != nil {
|
||||
t.Fatalf("create mod: %v", err)
|
||||
}
|
||||
if err := erf.Write(modFile, erf.New("MOD ", nil)); err != nil {
|
||||
t.Fatalf("write mod: %v", err)
|
||||
}
|
||||
if err := modFile.Close(); err != nil {
|
||||
t.Fatalf("close mod: %v", err)
|
||||
}
|
||||
|
||||
hakFile, err := os.Create(filepath.Join(root, "build", "vfx.hak"))
|
||||
if err != nil {
|
||||
t.Fatalf("create hak: %v", err)
|
||||
}
|
||||
if err := erf.Write(hakFile, erf.New("HAK ", []erf.Resource{
|
||||
{Name: "test_vfx", Type: 0x07D2, Data: []byte("mdl-data")},
|
||||
})); err != nil {
|
||||
t.Fatalf("write hak: %v", err)
|
||||
}
|
||||
if err := hakFile.Close(); err != nil {
|
||||
t.Fatalf("close hak: %v", err)
|
||||
}
|
||||
|
||||
_, err = Extract(p)
|
||||
if err == nil {
|
||||
t.Fatal("expected extract to fail")
|
||||
}
|
||||
if !strings.Contains(err.Error(), "paths.assets resolves to unsafe extraction root") {
|
||||
t.Fatalf("expected unsafe assets root error, got %v", err)
|
||||
}
|
||||
if _, statErr := os.Stat(filepath.Join(root, "mdl", "test_vfx.mdl")); !os.IsNotExist(statErr) {
|
||||
t.Fatalf("expected no root-level extracted asset, stat err=%v", statErr)
|
||||
}
|
||||
}
|
||||
|
||||
func TestExtractRefusesSourceWhenSourcePathIsUnset(t *testing.T) {
|
||||
root := t.TempDir()
|
||||
t.Chdir(root)
|
||||
mustMkdir(t, filepath.Join(root, "assets"))
|
||||
mustMkdir(t, filepath.Join(root, "build"))
|
||||
|
||||
mustWriteFile(t, filepath.Join(root, "nwn-tool.yaml"), `
|
||||
module:
|
||||
name: Test Module
|
||||
resref: testmod
|
||||
paths:
|
||||
assets: assets
|
||||
build: build
|
||||
`)
|
||||
|
||||
p, err := project.Load(root)
|
||||
if err != nil {
|
||||
t.Fatalf("load project: %v", err)
|
||||
}
|
||||
|
||||
modFile, err := os.Create(p.ModuleArchivePath())
|
||||
if err != nil {
|
||||
t.Fatalf("create mod: %v", err)
|
||||
}
|
||||
if err := erf.Write(modFile, erf.New("MOD ", []erf.Resource{
|
||||
{Name: "test_script", Type: 0x07D9, Data: []byte("void main() {}\n")},
|
||||
})); err != nil {
|
||||
t.Fatalf("write mod: %v", err)
|
||||
}
|
||||
if err := modFile.Close(); err != nil {
|
||||
t.Fatalf("close mod: %v", err)
|
||||
}
|
||||
|
||||
_, err = Extract(p)
|
||||
if err == nil {
|
||||
t.Fatal("expected extract to fail")
|
||||
}
|
||||
if !strings.Contains(err.Error(), "paths.source is not configured") {
|
||||
t.Fatalf("expected missing source path error, got %v", err)
|
||||
}
|
||||
if _, statErr := os.Stat(filepath.Join(root, "scripts", "test_script.nss")); !os.IsNotExist(statErr) {
|
||||
t.Fatalf("expected no root-level extracted script, stat err=%v", statErr)
|
||||
}
|
||||
}
|
||||
|
||||
func TestExtractConfiguredHAKDiscoveryIgnoresUnconfiguredArchives(t *testing.T) {
|
||||
root := t.TempDir()
|
||||
mustMkdir(t, filepath.Join(root, "src"))
|
||||
|
||||
Reference in New Issue
Block a user