package control import ( "context" "strings" "testing" ) type fakeRunner struct{} func (fakeRunner) Run(ctx context.Context, node Node, script string) (*CommandResult, error) { if strings.Contains(script, "HEALTHZ_HTTP_CODE=") { return &CommandResult{ Stdout: "{\"Service\":\"sing-box\",\"Status\":\"running\"}\nHEALTHZ_HTTP_CODE=200\n", }, nil } return &CommandResult{Stdout: "ok\n"}, nil } func (fakeRunner) Check(ctx context.Context, node Node) (*CommandResult, error) { return &CommandResult{Stdout: "ok"}, nil } func (fakeRunner) CopyFile(ctx context.Context, node Node, localPath, remotePath string) error { return nil } func TestUpgradeNode(t *testing.T) { t.Parallel() state, err := UpgradeNode(context.Background(), fakeRunner{}, Node{ ID: "nl-01", Name: "NL 01", Region: "nl", Host: "203.0.113.10", Domain: "nl-01.example.com", Enabled: true, SSH: SSHConfig{User: "root", Port: 22, Auth: "key", IdentityFile: "~/.ssh/id_ed25519"}, Protocols: []ProtocolProfile{ {Type: "vless", Enabled: true, Port: 443, TLS: &TLSProfile{Enabled: true, ServerName: "nl-01.example.com"}, Auth: &AuthProfile{UUID: "11111111-1111-1111-1111-111111111111"}, Extra: map[string]any{"path": "/ws"}}, }, }, t.TempDir()) if err != nil { t.Fatalf("UpgradeNode() error = %v", err) } if state == nil { t.Fatal("expected state") } if state.BootstrapStatus != "healthy" { t.Fatalf("BootstrapStatus = %q, want healthy", state.BootstrapStatus) } if got := state.Metadata["lifecycle_action"]; got != "upgrade" { t.Fatalf("lifecycle_action = %v, want upgrade", got) } }