feat(delivery): refine base service integrations

This commit is contained in:
mac
2026-07-29 16:36:27 +08:00
parent 2ca08f9360
commit 35875218c9
22 changed files with 1042 additions and 377 deletions
+29
View File
@@ -143,6 +143,35 @@ func TestRollbackExtraVarsTargetsOnlyTheAllocatedInstance(t *testing.T) {
}
}
func TestDirectoryPathsFromAWXStdout(t *testing.T) {
stdout := `
TASK [Show directory completions] **********************************************
ok: [db-01] => {
"stdout": "XINFRA_PATH_COMPLETIONS_JSON=[{\"path\":\"/a/bc\",\"available_gi\":12},{\"path\":\"/a/bb\",\"available_gi\":8}]"
}
`
items := directoryPathsFromAWXStdout(stdout)
if len(items) != 2 {
t.Fatalf("expected two completion items, got %#v", items)
}
if items[0].Path != "/a/bb" || items[1].Path != "/a/bc" {
t.Fatalf("items should be parsed and sorted by path: %#v", items)
}
}
func TestValidateDirectoryLookupPrefix(t *testing.T) {
for _, path := range []string{"/", "/a", "/a/b", "/lib/data"} {
if err := validateDirectoryLookupPrefix(path); err != nil {
t.Fatalf("valid path prefix %q rejected: %v", path, err)
}
}
for _, path := range []string{"a", "relative/path"} {
if err := validateDirectoryLookupPrefix(path); err == nil {
t.Fatalf("invalid path prefix %q was accepted", path)
}
}
}
func TestRegisterFailedIsProtectedFromRollback(t *testing.T) {
if !rollbackProtectedStatus(model.TaskRegisterFailed) {
t.Fatal("register_failed must preserve the healthy instance and resource usage")