feat: backend executor implement
This commit is contained in:
+31
-5
@@ -5,6 +5,7 @@ import (
|
||||
"context"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"yms-daemon/internal/daemonapi"
|
||||
@@ -38,6 +39,30 @@ func TestParseUpdateArgsAcceptsDirectNativeJAR(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestParseUpdateArgsAcceptsContainerImage(t *testing.T) {
|
||||
imageReference := "harbor.ymswell.asia/ymswell/glory-ymswell:20260813-184902-a37bf50d-v1.1.8.1"
|
||||
request, err := parseUpdateArgs([]string{"--service", "backend", "--container-image", imageReference}, &bytes.Buffer{})
|
||||
if err != nil {
|
||||
t.Fatalf("parse container backend update arguments: %v", err)
|
||||
}
|
||||
if request.service != "backend" || request.inputType != daemonapi.InputTypeContainerImage || request.imageReference != imageReference || request.file != "" {
|
||||
t.Fatalf("unexpected container backend update arguments: %+v", request)
|
||||
}
|
||||
}
|
||||
|
||||
func TestParseUpdateArgsRejectsNativeJARAndContainerImageTogether(t *testing.T) {
|
||||
jarPath := filepath.Join(t.TempDir(), "glory-soft-yms.jar")
|
||||
arguments := []string{
|
||||
"--service", "backend",
|
||||
"--native-jar", jarPath,
|
||||
"--container-image", "harbor.ymswell.asia/ymswell/glory-ymswell:20260813-184902-a37bf50d-v1.1.8.1",
|
||||
}
|
||||
_, err := parseUpdateArgs(arguments, &bytes.Buffer{})
|
||||
if err == nil || !strings.Contains(err.Error(), "exactly one") {
|
||||
t.Fatalf("expected mutually exclusive backend inputs, got %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestParseUpdateArgsAcceptsQuite(t *testing.T) {
|
||||
file := filepath.Join(t.TempDir(), "glory-soft-yms.jar")
|
||||
if err := os.WriteFile(file, []byte("jar"), 0o600); err != nil {
|
||||
@@ -86,11 +111,12 @@ func TestParseRestartArgsRejectsUnsupportedInput(t *testing.T) {
|
||||
|
||||
func TestParseUpdateArgsRejectsIncompleteOrUnsupportedInput(t *testing.T) {
|
||||
for name, arguments := range map[string][]string{
|
||||
"missing service": {"-f", "/tmp/package.zip"},
|
||||
"missing file": {"--service", "backend"},
|
||||
"other service": {"--service", "frontend", "-f", "/tmp/package.zip"},
|
||||
"positional": {"--service", "backend", "-f", "/tmp/package.zip", "extra"},
|
||||
"both inputs": {"--service", "backend", "-f", "/tmp/package.zip", "--native-jar", "/tmp/backend.jar"},
|
||||
"missing service": {"-f", "/tmp/package.zip"},
|
||||
"missing file": {"--service", "backend"},
|
||||
"other service": {"--service", "frontend", "-f", "/tmp/package.zip"},
|
||||
"positional": {"--service", "backend", "-f", "/tmp/package.zip", "extra"},
|
||||
"both inputs": {"--service", "backend", "-f", "/tmp/package.zip", "--native-jar", "/tmp/backend.jar"},
|
||||
"native and container": {"--service", "backend", "--native-jar", "/tmp/backend.jar", "--container-image", "repository:tag"},
|
||||
} {
|
||||
t.Run(name, func(t *testing.T) {
|
||||
if _, err := parseUpdateArgs(arguments, &bytes.Buffer{}); err == nil {
|
||||
|
||||
Reference in New Issue
Block a user