mirror of
https://github.com/Rain-kl/OpenFlare.git
synced 2026-10-09 00:56:37 +08:00
更新 .gitignore 文件以忽略数据目录,修改 DockerExecutor 的 RouteConfigDir 为绝对路径,并添加相应的单元测试
This commit is contained in:
@@ -0,0 +1 @@
|
|||||||
|
data
|
||||||
@@ -149,11 +149,15 @@ func NewExecutor(options ExecutorOptions) Executor {
|
|||||||
Runner: runner,
|
Runner: runner,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
routeConfigDir := filepath.Dir(options.RouteConfigPath)
|
||||||
|
if absDir, err := filepath.Abs(routeConfigDir); err == nil {
|
||||||
|
routeConfigDir = absDir
|
||||||
|
}
|
||||||
return &DockerExecutor{
|
return &DockerExecutor{
|
||||||
DockerBinary: options.DockerBinary,
|
DockerBinary: options.DockerBinary,
|
||||||
ContainerName: options.ContainerName,
|
ContainerName: options.ContainerName,
|
||||||
Image: options.Image,
|
Image: options.Image,
|
||||||
RouteConfigDir: filepath.Dir(options.RouteConfigPath),
|
RouteConfigDir: routeConfigDir,
|
||||||
Runner: runner,
|
Runner: runner,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import (
|
|||||||
"errors"
|
"errors"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"reflect"
|
"reflect"
|
||||||
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -112,3 +113,23 @@ func TestDockerExecutorStartsStoppedContainer(t *testing.T) {
|
|||||||
t.Fatalf("expected docker exec on third call, got %#v", runner.calls[2])
|
t.Fatalf("expected docker exec on third call, got %#v", runner.calls[2])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestNewExecutorUsesAbsoluteDockerMountPath(t *testing.T) {
|
||||||
|
executor := NewExecutor(ExecutorOptions{
|
||||||
|
DockerBinary: "docker",
|
||||||
|
ContainerName: "atsflare-nginx",
|
||||||
|
Image: "nginx:stable-alpine",
|
||||||
|
RouteConfigPath: "./data/etc/nginx/conf.d/atsflare_routes.conf",
|
||||||
|
})
|
||||||
|
|
||||||
|
dockerExecutor, ok := executor.(*DockerExecutor)
|
||||||
|
if !ok {
|
||||||
|
t.Fatal("expected docker executor")
|
||||||
|
}
|
||||||
|
if !filepath.IsAbs(dockerExecutor.RouteConfigDir) {
|
||||||
|
t.Fatalf("expected absolute route config dir, got %s", dockerExecutor.RouteConfigDir)
|
||||||
|
}
|
||||||
|
if !strings.HasSuffix(dockerExecutor.RouteConfigDir, filepath.Clean("data/etc/nginx/conf.d")) {
|
||||||
|
t.Fatalf("unexpected route config dir: %s", dockerExecutor.RouteConfigDir)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user