yao/engine/load_test.go
Max fabced291c fix: Enhance loading functions to handle non-existent directories
- Added checks in various loading functions to ignore processing if the respective directories do not exist, improving error handling and preventing unnecessary operations.
- Updated the Load function signature to return warnings alongside errors, allowing for better feedback on loading issues across different components.
2025-05-13 09:10:10 +08:00

74 lines
1.3 KiB
Go

package engine
import (
"os"
"testing"
"github.com/stretchr/testify/assert"
"github.com/yaoapp/gou/api"
"github.com/yaoapp/gou/application/yaz"
"github.com/yaoapp/yao/config"
"github.com/yaoapp/yao/pack"
)
func TestLoad(t *testing.T) {
defer Unload()
_, err := Load(config.Conf, LoadOption{})
assert.Nil(t, err)
assert.Greater(t, len(api.APIs), 0)
}
func TestReload(t *testing.T) {
defer Unload()
_, err := Load(config.Conf, LoadOption{})
assert.Nil(t, err)
Reload(config.Conf, LoadOption{})
assert.Nil(t, err)
assert.Greater(t, len(api.APIs), 0)
}
func TestLoadYaz(t *testing.T) {
defer Unload()
// package yaz
file, err := yaz.Pack(config.Conf.Root, pack.Cipher)
if err != nil {
t.Fatal(err)
}
defer os.Remove(file)
cfg := config.Conf
cfg.AppSource = file
_, err = Load(cfg, LoadOption{})
if err != nil {
t.Fatal(err)
}
assert.Greater(t, len(api.APIs), 0)
}
func TestReoadYaz(t *testing.T) {
defer Unload()
// package yaz
file, err := yaz.Pack(config.Conf.Root, pack.Cipher)
if err != nil {
t.Fatal(err)
}
defer os.Remove(file)
cfg := config.Conf
cfg.AppSource = file
_, err = Load(cfg, LoadOption{})
if err != nil {
t.Fatal(err)
}
assert.Greater(t, len(api.APIs), 0)
Reload(cfg, LoadOption{})
assert.Nil(t, err)
assert.Greater(t, len(api.APIs), 0)
}