90 lines
2.2 KiB
Go
90 lines
2.2 KiB
Go
package project
|
|
|
|
import (
|
|
"os"
|
|
"path/filepath"
|
|
"testing"
|
|
)
|
|
|
|
func TestTopDataAssetsDirPrefersExplicitConfig(t *testing.T) {
|
|
root := t.TempDir()
|
|
mkdirAll(t, filepath.Join(root, "src"))
|
|
mkdirAll(t, filepath.Join(root, "assets"))
|
|
mkdirAll(t, filepath.Join(root, "build"))
|
|
mkdirAll(t, filepath.Join(root, "custom-assets"))
|
|
|
|
proj := &Project{
|
|
Root: root,
|
|
Config: Config{
|
|
Module: ModuleConfig{Name: "Test", ResRef: "test"},
|
|
Paths: PathConfig{Source: "src", Assets: "assets", Build: "build"},
|
|
TopData: TopDataConfig{
|
|
Assets: "custom-assets",
|
|
},
|
|
},
|
|
}
|
|
|
|
result := proj.TopDataAssetsDir()
|
|
expected := filepath.Join(root, "custom-assets")
|
|
if result != expected {
|
|
t.Errorf("expected %s, got %s", expected, result)
|
|
}
|
|
}
|
|
|
|
func TestTopDataAssetsDirDoesNotAssumeSiblingRepo(t *testing.T) {
|
|
root := t.TempDir()
|
|
mkdirAll(t, filepath.Join(root, "src"))
|
|
mkdirAll(t, filepath.Join(root, "assets"))
|
|
mkdirAll(t, filepath.Join(root, "build"))
|
|
|
|
parentDir := filepath.Dir(root)
|
|
siblingPath := filepath.Join(parentDir, "sow-assets")
|
|
mkdirAll(t, siblingPath)
|
|
mkdirAll(t, filepath.Join(siblingPath, "assets", "part", "belt"))
|
|
|
|
proj := &Project{
|
|
Root: root,
|
|
Config: Config{
|
|
Module: ModuleConfig{Name: "Test", ResRef: "test"},
|
|
Paths: PathConfig{Source: "src", Assets: "assets", Build: "build"},
|
|
TopData: TopDataConfig{
|
|
Assets: "sow-assets",
|
|
},
|
|
},
|
|
}
|
|
|
|
result := proj.TopDataAssetsDir()
|
|
expected := filepath.Join(root, "sow-assets")
|
|
if result != expected {
|
|
t.Errorf("expected unresolved local path %s, got %s", expected, result)
|
|
}
|
|
}
|
|
|
|
func TestTopDataAssetsDirReturnsEmptyForNoConfig(t *testing.T) {
|
|
root := t.TempDir()
|
|
mkdirAll(t, filepath.Join(root, "src"))
|
|
mkdirAll(t, filepath.Join(root, "assets"))
|
|
mkdirAll(t, filepath.Join(root, "build"))
|
|
|
|
proj := &Project{
|
|
Root: root,
|
|
Config: Config{
|
|
Module: ModuleConfig{Name: "Test", ResRef: "test"},
|
|
Paths: PathConfig{Source: "src", Assets: "assets", Build: "build"},
|
|
TopData: TopDataConfig{},
|
|
},
|
|
}
|
|
|
|
result := proj.TopDataAssetsDir()
|
|
if result != "" {
|
|
t.Errorf("expected empty string, got %s", result)
|
|
}
|
|
}
|
|
|
|
func mkdirAll(t *testing.T, path string) {
|
|
t.Helper()
|
|
if err := os.MkdirAll(path, 0o755); err != nil {
|
|
t.Fatalf("mkdir %s: %v", path, err)
|
|
}
|
|
}
|