databricks-cli/cmd/selftest/parent.go

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

45 lines
1.0 KiB
Go
Raw Normal View History

2025-02-17 18:23:02 +00:00
package selftest
import (
"fmt"
"os"
"github.com/databricks/cli/libs/daemon"
"github.com/spf13/cobra"
)
const OutputFile = "DATABRICKS_CLI_SELFTEST_CHILD_OUTPUT_FILE"
func newParentCommand() *cobra.Command {
return &cobra.Command{
Use: "parent",
RunE: func(cmd *cobra.Command, args []string) error {
d := daemon.Daemon{
Env: os.Environ(),
Args: []string{"selftest", "child"},
LogFile: os.Getenv(OutputFile),
PidFilePath: "child.pid",
}
err := d.Start()
if err != nil {
return fmt.Errorf("failed to start child process: %w", err)
}
2025-02-18 12:14:29 +00:00
fmt.Println("[parent] started child")
2025-02-17 18:23:02 +00:00
err = d.WriteInput([]byte("Hello from the other side\n"))
if err != nil {
return fmt.Errorf("failed to write to child process: %w", err)
}
2025-02-18 12:14:29 +00:00
fmt.Println("[parent] input sent to child: Hello from the other side")
2025-02-17 18:23:02 +00:00
err = d.Release()
if err != nil {
return fmt.Errorf("failed to release child process: %w", err)
}
2025-02-18 12:14:29 +00:00
fmt.Println("[parent] exiting")
2025-02-17 18:23:02 +00:00
return nil
},
}
}