diff options
Diffstat (limited to 'extras/hs-test/infra/container.go')
-rw-r--r-- | extras/hs-test/infra/container.go | 40 |
1 files changed, 32 insertions, 8 deletions
diff --git a/extras/hs-test/infra/container.go b/extras/hs-test/infra/container.go index 019eec40f78..d4ef693c1c0 100644 --- a/extras/hs-test/infra/container.go +++ b/extras/hs-test/infra/container.go @@ -328,6 +328,7 @@ func (c *Container) getVolumesAsSlice() []string { } core_pattern, err := sysctl.Read("kernel.core_pattern") + core_pattern = strings.ReplaceAll(core_pattern, "%", "%%") if err == nil { if len(core_pattern) > 0 && core_pattern[0] != '|' { index := strings.LastIndex(core_pattern, "/") @@ -420,6 +421,19 @@ func (c *Container) CreateFile(destFileName string, content string) error { return nil } +func (c *Container) CreateFileInWorkDir(fileName string, contents string) error { + file, err := os.Create(c.GetHostWorkDir() + "/" + fileName) + if err != nil { + return err + } + defer file.Close() + _, err = file.Write([]byte(contents)) + if err != nil { + return err + } + return nil +} + func (c *Container) GetFile(sourceFileName, targetFileName string) error { cmd := exec.Command("docker", "cp", c.Name+":"+sourceFileName, targetFileName) return cmd.Run() @@ -429,19 +443,29 @@ func (c *Container) GetFile(sourceFileName, targetFileName string) error { * Executes in detached mode so that the started application can continue to run * without blocking execution of test */ -func (c *Container) ExecServer(command string, arguments ...any) { +func (c *Container) ExecServer(useEnvVars bool, command string, arguments ...any) { + var envVars string serverCommand := fmt.Sprintf(command, arguments...) - containerExecCommand := "docker exec -d" + c.getEnvVarsAsCliOption() + - " " + c.Name + " " + serverCommand + if useEnvVars { + envVars = c.getEnvVarsAsCliOption() + } else { + envVars = "" + } + containerExecCommand := fmt.Sprintf("docker exec -d %s %s %s", envVars, c.Name, serverCommand) GinkgoHelper() c.Suite.Log(containerExecCommand) c.Suite.AssertNil(exechelper.Run(containerExecCommand)) } -func (c *Container) Exec(command string, arguments ...any) string { - cliCommand := fmt.Sprintf(command, arguments...) - containerExecCommand := "docker exec" + c.getEnvVarsAsCliOption() + - " " + c.Name + " " + cliCommand +func (c *Container) Exec(useEnvVars bool, command string, arguments ...any) string { + var envVars string + serverCommand := fmt.Sprintf(command, arguments...) + if useEnvVars { + envVars = c.getEnvVarsAsCliOption() + } else { + envVars = "" + } + containerExecCommand := fmt.Sprintf("docker exec %s %s %s", envVars, c.Name, serverCommand) GinkgoHelper() c.Suite.Log(containerExecCommand) byteOutput, err := exechelper.CombinedOutput(containerExecCommand) @@ -518,7 +542,7 @@ func (c *Container) stop() error { return nil } -func (c *Container) CreateConfig(targetConfigName string, templateName string, values any) { +func (c *Container) CreateConfigFromTemplate(targetConfigName string, templateName string, values any) { template := template.Must(template.ParseFiles(templateName)) f, err := os.CreateTemp(logDir, "hst-config") |