feat: backend executor implement
This commit is contained in:
@@ -7,7 +7,10 @@ import (
|
||||
"testing"
|
||||
)
|
||||
|
||||
const validNativeConfig = `[backend]
|
||||
const validNativeConfig = `[daemon]
|
||||
environment = "dev"
|
||||
|
||||
[backend]
|
||||
type = "native"
|
||||
release_dir = "/home/yms/lib/releases"
|
||||
active_jar = "/home/yms/lib/glory-soft-yms.jar"
|
||||
@@ -24,6 +27,22 @@ jar = "/home/yms/lib/glory-soft-yms-8081.jar"
|
||||
health_endpoint = "http://127.0.0.1:8081/yms/actuator/health"
|
||||
`
|
||||
|
||||
const validContainerConfig = `[daemon]
|
||||
environment = "dev"
|
||||
|
||||
[backend]
|
||||
type = "container"
|
||||
systemctl_path = "/bin/systemctl"
|
||||
|
||||
[backend.slot.8080]
|
||||
container_name = "backend-8080"
|
||||
health_endpoint = "http://127.0.0.1:8080/yms/actuator/health"
|
||||
|
||||
[backend.slot.8081]
|
||||
container_name = "backend-8081"
|
||||
health_endpoint = "http://127.0.0.1:8081/yms/actuator/health"
|
||||
`
|
||||
|
||||
func TestLoadValidNativeConfiguration(t *testing.T) {
|
||||
path := writeConfig(t, validNativeConfig)
|
||||
|
||||
@@ -31,6 +50,9 @@ func TestLoadValidNativeConfiguration(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatalf("load native deployment configuration: %v", err)
|
||||
}
|
||||
if config.Daemon.Environment != EnvironmentDev {
|
||||
t.Fatalf("unexpected daemon configuration: %+v", config.Daemon)
|
||||
}
|
||||
if config.Backend.Type != BackendTypeNative || config.Backend.SystemctlPath != "/bin/systemctl" {
|
||||
t.Fatalf("unexpected backend configuration: %+v", config.Backend)
|
||||
}
|
||||
@@ -50,6 +72,27 @@ func TestLoadValidNativeConfiguration(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestLoadValidContainerConfiguration(t *testing.T) {
|
||||
config, err := Load(writeConfig(t, validContainerConfig))
|
||||
if err != nil {
|
||||
t.Fatalf("load container deployment configuration: %v", err)
|
||||
}
|
||||
if config.Backend.Type != BackendTypeContainer {
|
||||
t.Fatalf("unexpected backend type: %q", config.Backend.Type)
|
||||
}
|
||||
if config.Backend.Slot.Port8080.ContainerName != "backend-8080" || config.Backend.Slot.Port8081.ContainerName != "backend-8081" {
|
||||
t.Fatalf("unexpected container slots: %+v", config.Backend.Slot)
|
||||
}
|
||||
}
|
||||
|
||||
func TestLoadRejectsChangedContainerName(t *testing.T) {
|
||||
content := strings.Replace(validContainerConfig, `container_name = "backend-8081"`, `container_name = "backend"`, 1)
|
||||
_, err := Load(writeConfig(t, content))
|
||||
if err == nil || !strings.Contains(err.Error(), "backend.slot.8081.container_name") {
|
||||
t.Fatalf("expected exact container name rejection, got %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestPackagedNativeConfigurationMatchesContract(t *testing.T) {
|
||||
path, err := filepath.Abs(filepath.Join("..", "..", "packaging", "etc", "yms-daemon", "yms-daemon.toml"))
|
||||
if err != nil {
|
||||
@@ -68,6 +111,41 @@ func TestLoadRejectsUnknownField(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestLoadAcceptsProductionEnvironment(t *testing.T) {
|
||||
content := strings.Replace(validNativeConfig, `environment = "dev"`, `environment = "prod"`, 1)
|
||||
config, err := Load(writeConfig(t, content))
|
||||
if err != nil {
|
||||
t.Fatalf("load production environment: %v", err)
|
||||
}
|
||||
if config.Daemon.Environment != EnvironmentProd {
|
||||
t.Fatalf("unexpected daemon environment: %q", config.Daemon.Environment)
|
||||
}
|
||||
}
|
||||
|
||||
func TestLoadRejectsMissingDaemonTable(t *testing.T) {
|
||||
content := strings.Replace(validNativeConfig, "[daemon]\nenvironment = \"dev\"\n\n", "", 1)
|
||||
_, err := Load(writeConfig(t, content))
|
||||
if err == nil || !strings.Contains(err.Error(), "daemon table is required") {
|
||||
t.Fatalf("expected missing daemon table rejection, got %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestLoadRejectsChangedEnvironment(t *testing.T) {
|
||||
content := strings.Replace(validNativeConfig, `environment = "dev"`, `environment = "development"`, 1)
|
||||
_, err := Load(writeConfig(t, content))
|
||||
if err == nil || !strings.Contains(err.Error(), "daemon.environment") {
|
||||
t.Fatalf("expected exact daemon environment rejection, got %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestLoadRejectsUnknownDaemonField(t *testing.T) {
|
||||
content := strings.Replace(validNativeConfig, `environment = "dev"`, "environment = \"dev\"\nEnvironment = \"dev\"", 1)
|
||||
_, err := Load(writeConfig(t, content))
|
||||
if err == nil || !strings.Contains(err.Error(), "daemon.Environment") {
|
||||
t.Fatalf("expected exact daemon field rejection, got %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestLoadRejectsWrongTableCase(t *testing.T) {
|
||||
content := strings.Replace(validNativeConfig, "[backend]", "[Backend]", 1)
|
||||
_, err := Load(writeConfig(t, content))
|
||||
|
||||
Reference in New Issue
Block a user