增加支付逻辑
This commit is contained in:
1 parent
4ac786aafb
commit
dfb2c91b8d
77 files changed
+6370
-45
No files matched your search
@@ -14,6 +14,7 @@ import (
|
||||
"time"
|
||||
|
||||
"git.nianxx.cn/wangxuming/NianAIGC/backend/internal/application"
|
||||
"git.nianxx.cn/wangxuming/NianAIGC/backend/internal/migrations"
|
||||
"git.nianxx.cn/wangxuming/NianAIGC/backend/internal/settings"
|
||||
)
|
||||
|
||||
@@ -33,9 +34,9 @@ func run() error {
|
||||
if err != nil {
|
||||
return fmt.Errorf("load Go backend runtime settings: %w", err)
|
||||
}
|
||||
app, err := application.New(application.Options{Context: ctx, Getenv: getenv})
|
||||
app, err := initializeApplication(ctx, getenv)
|
||||
if err != nil {
|
||||
return fmt.Errorf("initialize Go backend: %w", err)
|
||||
return err
|
||||
}
|
||||
defer app.Close()
|
||||
|
||||
@@ -71,6 +72,19 @@ func run() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// Complete schema updates before constructing services, bootstrapping accounts,
|
||||
// starting background workers, or opening the HTTP listener.
|
||||
func initializeApplication(ctx context.Context, getenv func(string) string) (*application.App, error) {
|
||||
if err := migrations.Run(ctx, getenv); err != nil {
|
||||
return nil, fmt.Errorf("migrate database before startup: %w", err)
|
||||
}
|
||||
app, err := application.New(application.Options{Context: ctx, Getenv: getenv})
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("initialize Go backend: %w", err)
|
||||
}
|
||||
return app, nil
|
||||
}
|
||||
|
||||
func runtimeGetenv(process func(string) string) (func(string) string, error) {
|
||||
path := strings.TrimSpace(process("ZHINIAN_SETTINGS_FILE"))
|
||||
if path == "" {
|
||||
|
||||
@@ -1,11 +1,34 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestInitializeApplicationFailsBeforeCreatingServicesWhenMigrationIsInvalid(t *testing.T) {
|
||||
runtimeDir := filepath.Join(t.TempDir(), "not-created")
|
||||
values := map[string]string{
|
||||
"DATABASE_AUTO_MIGRATE": "true",
|
||||
"ZHINIAN_DATA_BACKEND": "local",
|
||||
"ZHINIAN_RUNTIME_DIR": runtimeDir,
|
||||
"ZHINIAN_AUTH_REQUIRED": "false",
|
||||
}
|
||||
app, err := initializeApplication(context.Background(), func(name string) string { return values[name] })
|
||||
if app != nil {
|
||||
app.Close()
|
||||
t.Fatal("application was created despite invalid migration configuration")
|
||||
}
|
||||
if err == nil || !strings.Contains(err.Error(), "migrate database before startup:") {
|
||||
t.Fatalf("expected migration failure before application initialization, got %v", err)
|
||||
}
|
||||
if _, err := os.Stat(runtimeDir); !os.IsNotExist(err) {
|
||||
t.Fatalf("application startup touched runtime storage before migration succeeded: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestListenAddressDefaultsToLoopbackAndSupportsExplicitBinding(t *testing.T) {
|
||||
if got := listenAddress(func(string) string { return "" }); got != "127.0.0.1:8080" {
|
||||
t.Fatalf("listenAddress(defaults) = %q", got)
|
||||
|
||||
Reference in new issue
Block a user