Refactor build and topdata path resolution through project config
This commit is contained in:
@@ -175,6 +175,141 @@ func TestExtractReadsHAKAssets(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestExtractDeletesConsumedModuleArchiveAfterSuccessWhenConfigured(t *testing.T) {
|
||||
root := t.TempDir()
|
||||
mustMkdir(t, filepath.Join(root, "src", "module"))
|
||||
mustMkdir(t, filepath.Join(root, "assets"))
|
||||
mustMkdir(t, filepath.Join(root, "build"))
|
||||
|
||||
mustWriteFile(t, filepath.Join(root, "nwn-tool.json"), `{
|
||||
"module": {
|
||||
"name": "Test Module",
|
||||
"resref": "testmod"
|
||||
},
|
||||
"paths": {
|
||||
"source": "src",
|
||||
"assets": "assets",
|
||||
"build": "build"
|
||||
},
|
||||
"extract": {
|
||||
"delete_module_archive_after_success": true
|
||||
}
|
||||
}
|
||||
`)
|
||||
mustWriteFile(t, filepath.Join(root, "src", "module", "module.ifo.json"), `{
|
||||
"file_type": "IFO ",
|
||||
"file_version": "V3.2",
|
||||
"root": {
|
||||
"struct_type": 0,
|
||||
"fields": [
|
||||
{
|
||||
"label": "Mod_Name",
|
||||
"type": "CExoString",
|
||||
"value": "Original Module"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
`)
|
||||
|
||||
p, err := project.Load(root)
|
||||
if err != nil {
|
||||
t.Fatalf("load project: %v", err)
|
||||
}
|
||||
if err := p.ValidateLayout(); err != nil {
|
||||
t.Fatalf("validate layout: %v", err)
|
||||
}
|
||||
if err := p.Scan(); err != nil {
|
||||
t.Fatalf("scan: %v", err)
|
||||
}
|
||||
|
||||
buildResult, err := BuildModule(p)
|
||||
if err != nil {
|
||||
t.Fatalf("build module: %v", err)
|
||||
}
|
||||
if err := os.Remove(filepath.Join(root, "src", "module", "module.ifo.json")); err != nil {
|
||||
t.Fatalf("remove source file: %v", err)
|
||||
}
|
||||
if err := p.Scan(); err != nil {
|
||||
t.Fatalf("rescan: %v", err)
|
||||
}
|
||||
|
||||
result, err := Extract(p)
|
||||
if err != nil {
|
||||
t.Fatalf("extract: %v", err)
|
||||
}
|
||||
if len(result.DeletedArchivePaths) != 1 {
|
||||
t.Fatalf("expected 1 deleted archive path, got %#v", result.DeletedArchivePaths)
|
||||
}
|
||||
if result.DeletedArchivePaths[0] != buildResult.ModulePath {
|
||||
t.Fatalf("expected deleted archive %s, got %#v", buildResult.ModulePath, result.DeletedArchivePaths)
|
||||
}
|
||||
if _, err := os.Stat(buildResult.ModulePath); !os.IsNotExist(err) {
|
||||
t.Fatalf("expected consumed module archive to be removed, stat err=%v", err)
|
||||
}
|
||||
if _, err := os.Stat(filepath.Join(root, "src", "module", "module.ifo.json")); err != nil {
|
||||
t.Fatalf("expected extracted module file: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestExtractKeepsConsumedModuleArchiveWhenExtractionFails(t *testing.T) {
|
||||
root := t.TempDir()
|
||||
mustMkdir(t, filepath.Join(root, "src"))
|
||||
mustMkdir(t, filepath.Join(root, "assets"))
|
||||
mustMkdir(t, filepath.Join(root, "build"))
|
||||
|
||||
mustWriteFile(t, filepath.Join(root, "nwn-tool.json"), `{
|
||||
"module": {
|
||||
"name": "Test Module",
|
||||
"resref": "testmod"
|
||||
},
|
||||
"paths": {
|
||||
"source": "src",
|
||||
"assets": "assets",
|
||||
"build": "build"
|
||||
},
|
||||
"extract": {
|
||||
"delete_module_archive_after_success": true
|
||||
}
|
||||
}
|
||||
`)
|
||||
|
||||
p, err := project.Load(root)
|
||||
if err != nil {
|
||||
t.Fatalf("load project: %v", err)
|
||||
}
|
||||
if err := p.ValidateLayout(); err != nil {
|
||||
t.Fatalf("validate layout: %v", err)
|
||||
}
|
||||
if err := p.Scan(); err != nil {
|
||||
t.Fatalf("scan: %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: "broken", Type: 0xFFFF, Data: []byte("bad")},
|
||||
})); err != nil {
|
||||
t.Fatalf("write mod: %v", err)
|
||||
}
|
||||
if err := modFile.Close(); err != nil {
|
||||
t.Fatalf("close mod: %v", err)
|
||||
}
|
||||
|
||||
result, err := Extract(p)
|
||||
if err == nil {
|
||||
t.Fatal("expected extract to fail")
|
||||
}
|
||||
if len(result.DeletedArchivePaths) != 0 {
|
||||
t.Fatalf("expected no deleted archive paths, got %#v", result.DeletedArchivePaths)
|
||||
}
|
||||
if _, statErr := os.Stat(p.ModuleArchivePath()); statErr != nil {
|
||||
t.Fatalf("expected consumed module archive to remain after failed extract, stat err=%v", statErr)
|
||||
}
|
||||
}
|
||||
|
||||
func TestBuildSplitsConfiguredHAKs(t *testing.T) {
|
||||
root := t.TempDir()
|
||||
mustMkdir(t, filepath.Join(root, "src"))
|
||||
|
||||
Reference in New Issue
Block a user