Skip to content

Commit

Permalink
test/e2e/framework:refactor generateWriteBlockCmd due to the same fun…
Browse files Browse the repository at this point in the history
…ction
  • Loading branch information
tanjunchen committed Jan 14, 2020
1 parent f4db821 commit b60703c
Showing 1 changed file with 18 additions and 19 deletions.
37 changes: 18 additions & 19 deletions test/e2e/framework/volume/fixtures.go
Original file line number Diff line number Diff line change
Expand Up @@ -543,30 +543,36 @@ 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}
commands = []string{"powershell", "/c", "echo '" + content + "' > " + path}
}
return commands
}

// generateWriteFileCmd generates the corresponding command lines to write a file with the given content and file path.
// generateReadBlockCmd generates the corresponding command lines to read from a block device with the given 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 {
func generateReadBlockCmd(fullPath string, numberOfCharacters int) []string {
var commands []string
if !framework.NodeOSDistroIs("windows") {
commands = []string{"/bin/sh", "-c", "echo '" + content + "' > " + fullPath}
commands = []string{"head", "-c", strconv.Itoa(numberOfCharacters), fullPath}
} else {
commands = []string{"powershell", "/c", "echo '" + content + "' > " + fullPath}
// TODO: is there a way on windows to get the first X bytes from a device?
commands = []string{"powershell", "/c", "type " + fullPath}
}
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 {
Expand All @@ -579,17 +585,10 @@ func generateReadFileCmd(fullPath string) []string {
return commands
}

// generateReadBlockCmd generates the corresponding command lines to read from a block device with the given file path.
// 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 generateReadBlockCmd(fullPath string, numberOfCharacters int) []string {
var commands []string
if !framework.NodeOSDistroIs("windows") {
commands = []string{"head", "-c", strconv.Itoa(numberOfCharacters), fullPath}
} else {
// TODO: is there a way on windows to get the first X bytes from a device?
commands = []string{"powershell", "/c", "type " + fullPath}
}
return commands
func generateWriteFileCmd(content, fullPath string) []string {
return generateWriteCmd(content, fullPath)
}

// GenerateSecurityContext generates the corresponding container security context with the given inputs
Expand Down

0 comments on commit b60703c

Please sign in to comment.