86 lines
4.9 KiB
Go
86 lines
4.9 KiB
Go
package panel
|
|
|
|
import (
|
|
"context"
|
|
"sync"
|
|
)
|
|
|
|
type Mock struct {
|
|
mu sync.Mutex
|
|
next int64
|
|
}
|
|
|
|
func NewMock() *Mock { return &Mock{next: 1000} }
|
|
func (m *Mock) id() int64 { m.mu.Lock(); defer m.mu.Unlock(); m.next++; return m.next }
|
|
func (*Mock) Ping(context.Context) error { return nil }
|
|
func (*Mock) RuntimeCapabilities(context.Context) (RuntimeCapabilities, error) {
|
|
versions := RuntimeCatalog{
|
|
"PHP": {"8.4", "8.2", "8.1"},
|
|
"Node.js": {"v22.23.3", "v20.19.5"},
|
|
"Python": {"3.12.3", "3.11.9"},
|
|
"Go": {"go1.25.4", "go1.24.10"},
|
|
"Java": {"jdk-21.0.2", "jdk-17.0.12"},
|
|
}
|
|
capabilities := make(RuntimeCapabilities, len(versions))
|
|
for runtime, items := range versions {
|
|
policy := PolicyFreeProject
|
|
if runtime == "PHP" {
|
|
policy = PolicyFreeCore
|
|
}
|
|
capabilities[runtime] = RuntimeCapability{Status: RuntimeAvailable, Versions: items, Policy: policy}
|
|
}
|
|
return capabilities, nil
|
|
}
|
|
func (m *Mock) RuntimeCatalog(ctx context.Context) (RuntimeCatalog, error) {
|
|
capabilities, err := m.RuntimeCapabilities(ctx)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
catalog := make(RuntimeCatalog, len(capabilities))
|
|
for runtime, capability := range capabilities {
|
|
catalog[runtime] = capability.Versions
|
|
}
|
|
return catalog, nil
|
|
}
|
|
func (*Mock) RuntimeEnvironments(context.Context) ([]RuntimeEnvironment, error) {
|
|
return []RuntimeEnvironment{
|
|
{Name: "PHP", ComponentTitle: "PHP 运行环境", ComponentStatus: RuntimeComponentReady, Installed: []string{"8.4", "8.2"}, Available: []string{}, Installing: []string{}},
|
|
{Name: "Node.js", ComponentTitle: "Node.js 版本管理器", ComponentStatus: RuntimeComponentReady, Installed: []string{"v22.23.3"}, Available: []string{"v24.12.0", "v22.23.3"}, Installing: []string{}, Recommended: "v24.12.0"},
|
|
{Name: "Python", ComponentTitle: "Python 项目管理器", ComponentStatus: RuntimeComponentReady, Installed: []string{"3.12.3"}, Available: []string{"3.13.1", "3.12.3"}, Installing: []string{}, Recommended: "3.13.1"},
|
|
{Name: "Go", ComponentTitle: "Go 项目环境", ComponentStatus: RuntimeComponentReady, Installed: []string{"go1.25.4"}, Available: []string{"go1.26.1", "go1.25.4"}, Installing: []string{}, Recommended: "go1.26.1"},
|
|
{Name: "Java", ComponentTitle: "Java 项目环境", ComponentStatus: RuntimeComponentReady, Installed: []string{"jdk-21.0.2"}, Available: []string{"jdk-25.0.1", "jdk-21.0.2"}, Installing: []string{}, Recommended: "jdk-25.0.1"},
|
|
}, nil
|
|
}
|
|
func (*Mock) InstallRuntimeComponent(context.Context, string) error { return nil }
|
|
func (*Mock) InstallRuntimeEnvironment(context.Context, string, string) error { return nil }
|
|
func (m *Mock) CreateSite(context.Context, SiteSpec) (int64, error) { return m.id(), nil }
|
|
func (*Mock) ListUnmanagedSites(context.Context) ([]ExistingSite, error) {
|
|
return []ExistingSite{}, nil
|
|
}
|
|
func (*Mock) AdoptSite(context.Context, int64, string, SiteSpec) error { return nil }
|
|
func (*Mock) RollbackAdoption(context.Context, int64, string, string) error { return nil }
|
|
func (*Mock) SetSitePath(context.Context, int64, string) error { return nil }
|
|
func (m *Mock) SetSiteRunPath(context.Context, int64, string) error { return nil }
|
|
func (m *Mock) MigrateRuntimeIdentity(context.Context, int64, string, bool) error { return nil }
|
|
func (*Mock) DeleteSite(context.Context, int64, string) error { return nil }
|
|
func (*Mock) AddDomain(context.Context, int64, string, string) error { return nil }
|
|
func (*Mock) DeleteDomain(context.Context, int64, string, string) error { return nil }
|
|
func (m *Mock) CreateFTP(context.Context, string, string, string, int64) (int64, error) {
|
|
return m.id(), nil
|
|
}
|
|
func (*Mock) DeleteFTP(context.Context, int64, string) error { return nil }
|
|
func (*Mock) SetFTPState(context.Context, int64, string, bool) error { return nil }
|
|
func (m *Mock) CreateDatabase(context.Context, string, string, string, int64) (int64, error) {
|
|
return m.id(), nil
|
|
}
|
|
func (*Mock) DeleteDatabase(context.Context, int64, string) error { return nil }
|
|
func (*Mock) DatabaseSize(context.Context, int64, string) (uint64, error) { return 0, nil }
|
|
func (*Mock) ConfigureRuntime(context.Context, RuntimeSpec) error { return nil }
|
|
func (*Mock) RemoveRuntime(context.Context, RuntimeSpec) error { return nil }
|
|
func (*Mock) SetRuntimeState(context.Context, RuntimeSpec, bool) error { return nil }
|
|
func (*Mock) ConfigureProxy(context.Context, int64, string, int) error { return nil }
|
|
func (*Mock) RequestCertificate(context.Context, int64, string, []string) error { return nil }
|
|
func (*Mock) InstallCertificate(context.Context, int64, string, string, string) error { return nil }
|
|
func (*Mock) DisableCertificate(context.Context, int64, string) error { return nil }
|
|
func (*Mock) SetSiteState(context.Context, int64, string, bool) error { return nil }
|