mirror of
https://github.com/Rain-kl/OpenFlare.git
synced 2026-10-11 01:36:37 +08:00
更新 DockerExecutor 的 Test 和 Reload 方法,优化容器启动逻辑,调整测试用例以反映新行为
This commit is contained in:
@@ -64,10 +64,17 @@ type DockerExecutor struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (e *DockerExecutor) Test(ctx context.Context) error {
|
func (e *DockerExecutor) Test(ctx context.Context) error {
|
||||||
if err := e.EnsureRuntime(ctx, false); err != nil {
|
output, err := e.Runner.Run(
|
||||||
return err
|
ctx,
|
||||||
}
|
e.DockerBinary,
|
||||||
output, err := e.Runner.Run(ctx, e.DockerBinary, "exec", e.ContainerName, "nginx", "-t")
|
"run",
|
||||||
|
"--rm",
|
||||||
|
"-v",
|
||||||
|
fmt.Sprintf("%s:/etc/nginx/conf.d", e.RouteConfigDir),
|
||||||
|
e.Image,
|
||||||
|
"nginx",
|
||||||
|
"-t",
|
||||||
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("docker nginx -t failed: %w: %s", err, string(output))
|
return fmt.Errorf("docker nginx -t failed: %w: %s", err, string(output))
|
||||||
}
|
}
|
||||||
@@ -75,14 +82,7 @@ func (e *DockerExecutor) Test(ctx context.Context) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (e *DockerExecutor) Reload(ctx context.Context) error {
|
func (e *DockerExecutor) Reload(ctx context.Context) error {
|
||||||
if err := e.EnsureRuntime(ctx, false); err != nil {
|
return e.EnsureRuntime(ctx, true)
|
||||||
return err
|
|
||||||
}
|
|
||||||
output, err := e.Runner.Run(ctx, e.DockerBinary, "exec", e.ContainerName, "nginx", "-s", "reload")
|
|
||||||
if err != nil {
|
|
||||||
return fmt.Errorf("docker nginx reload failed: %w: %s", err, string(output))
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (e *DockerExecutor) EnsureRuntime(ctx context.Context, recreate bool) error {
|
func (e *DockerExecutor) EnsureRuntime(ctx context.Context, recreate bool) error {
|
||||||
|
|||||||
@@ -81,14 +81,11 @@ func TestDockerExecutorStartsContainerWhenMissing(t *testing.T) {
|
|||||||
t.Fatalf("Test failed: %v", err)
|
t.Fatalf("Test failed: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(runner.calls) != 3 {
|
if len(runner.calls) != 1 {
|
||||||
t.Fatalf("expected 3 calls, got %d", len(runner.calls))
|
t.Fatalf("expected 1 call, got %d", len(runner.calls))
|
||||||
}
|
}
|
||||||
if runner.calls[1].args[0] != "run" {
|
if runner.calls[0].args[0] != "run" || runner.calls[0].args[1] != "--rm" {
|
||||||
t.Fatalf("expected docker run on second call, got %#v", runner.calls[1])
|
t.Fatalf("expected docker run --rm for test, got %#v", runner.calls[0])
|
||||||
}
|
|
||||||
if runner.calls[2].args[0] != "exec" {
|
|
||||||
t.Fatalf("expected docker exec on third call, got %#v", runner.calls[2])
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -113,8 +110,11 @@ func TestDockerExecutorStartsStoppedContainer(t *testing.T) {
|
|||||||
t.Fatalf("Reload failed: %v", err)
|
t.Fatalf("Reload failed: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(runner.calls) != 4 {
|
if len(runner.calls) != 3 {
|
||||||
t.Fatalf("expected 4 calls, got %d", len(runner.calls))
|
t.Fatalf("expected 3 calls, got %d", len(runner.calls))
|
||||||
|
}
|
||||||
|
if runner.calls[0].args[0] != "inspect" {
|
||||||
|
t.Fatalf("expected docker inspect on first call, got %#v", runner.calls[0])
|
||||||
}
|
}
|
||||||
if runner.calls[1].args[0] != "rm" {
|
if runner.calls[1].args[0] != "rm" {
|
||||||
t.Fatalf("expected docker rm on second call, got %#v", runner.calls[1])
|
t.Fatalf("expected docker rm on second call, got %#v", runner.calls[1])
|
||||||
@@ -122,9 +122,6 @@ func TestDockerExecutorStartsStoppedContainer(t *testing.T) {
|
|||||||
if runner.calls[2].args[0] != "run" {
|
if runner.calls[2].args[0] != "run" {
|
||||||
t.Fatalf("expected docker run on third call, got %#v", runner.calls[2])
|
t.Fatalf("expected docker run on third call, got %#v", runner.calls[2])
|
||||||
}
|
}
|
||||||
if runner.calls[3].args[0] != "exec" {
|
|
||||||
t.Fatalf("expected docker exec on fourth call, got %#v", runner.calls[3])
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestDockerExecutorRecreatesContainerOnStartup(t *testing.T) {
|
func TestDockerExecutorRecreatesContainerOnStartup(t *testing.T) {
|
||||||
|
|||||||
Reference in New Issue
Block a user