From b60703c1724f39312b050bdb5f20497f9e642d89 Mon Sep 17 00:00:00 2001 From: tanjunchen <2799194073@qq.com> Date: Tue, 14 Jan 2020 14:56:42 +0800 Subject: [PATCH] test/e2e/framework:refactor generateWriteBlockCmd due to the same function --- test/e2e/framework/volume/fixtures.go | 57 +++++++++++++-------------- 1 file changed, 28 insertions(+), 29 deletions(-) diff --git a/test/e2e/framework/volume/fixtures.go b/test/e2e/framework/volume/fixtures.go index 35be9d04d96..9ba32930ee2 100644 --- a/test/e2e/framework/volume/fixtures.go +++ b/test/e2e/framework/volume/fixtures.go @@ -543,38 +543,13 @@ func GenerateScriptCmd(command string) []string { return commands } -// generateWriteBlockCmd generates the corresponding command lines to write to a block device the given content. -// Depending on the Node OS is Windows or linux, the command will use powershell or /bin/sh -func generateWriteBlockCmd(content, fullPath string) []string { +// generateWriteCmd is used by generateWriteBlockCmd and generateWriteFileCmd +func generateWriteCmd(content, path string) []string { var commands []string if !framework.NodeOSDistroIs("windows") { - commands = []string{"/bin/sh", "-c", "echo '" + content + "' > " + fullPath} + commands = []string{"/bin/sh", "-c", "echo '" + content + "' > " + path} } else { - commands = []string{"powershell", "/c", "echo '" + content + "' > " + fullPath} - } - return commands -} - -// generateWriteFileCmd generates the corresponding command lines to write a file with the given content and file path. -// Depending on the Node OS is Windows or linux, the command will use powershell or /bin/sh -func generateWriteFileCmd(content, fullPath string) []string { - var commands []string - if !framework.NodeOSDistroIs("windows") { - commands = []string{"/bin/sh", "-c", "echo '" + content + "' > " + fullPath} - } else { - commands = []string{"powershell", "/c", "echo '" + content + "' > " + fullPath} - } - return commands -} - -// generateReadFileCmd generates the corresponding command lines to read from a file with the given file path. -// Depending on the Node OS is Windows or linux, the command will use powershell or /bin/sh -func generateReadFileCmd(fullPath string) []string { - var commands []string - if !framework.NodeOSDistroIs("windows") { - commands = []string{"cat", fullPath} - } else { - commands = []string{"powershell", "/c", "type " + fullPath} + commands = []string{"powershell", "/c", "echo '" + content + "' > " + path} } return commands } @@ -592,6 +567,30 @@ func generateReadBlockCmd(fullPath string, numberOfCharacters int) []string { return commands } +// generateWriteBlockCmd generates the corresponding command lines to write to a block device the given content. +// Depending on the Node OS is Windows or linux, the command will use powershell or /bin/sh +func generateWriteBlockCmd(content, fullPath string) []string { + return generateWriteCmd(content, fullPath) +} + +// generateReadFileCmd generates the corresponding command lines to read from a file with the given file path. +// Depending on the Node OS is Windows or linux, the command will use powershell or /bin/sh +func generateReadFileCmd(fullPath string) []string { + var commands []string + if !framework.NodeOSDistroIs("windows") { + commands = []string{"cat", fullPath} + } else { + commands = []string{"powershell", "/c", "type " + fullPath} + } + return commands +} + +// generateWriteFileCmd generates the corresponding command lines to write a file with the given content and file path. +// Depending on the Node OS is Windows or linux, the command will use powershell or /bin/sh +func generateWriteFileCmd(content, fullPath string) []string { + return generateWriteCmd(content, fullPath) +} + // GenerateSecurityContext generates the corresponding container security context with the given inputs // If the Node OS is windows, currently we will ignore the inputs and return nil. // TODO: Will modify it after windows has its own security context