Skip to content
This repository has been archived by the owner on May 6, 2020. It is now read-only.

Commit

Permalink
tests: Simplify makeRuntimeConfig
Browse files Browse the repository at this point in the history
Create a new makeVersionBinary() function to allow makeRuntimeConfig() to
be simplified.

Signed-off-by: James O. D. Hunt <[email protected]>
  • Loading branch information
jodh-intel committed Sep 12, 2017
1 parent c94e0ab commit 41abb89
Showing 1 changed file with 21 additions and 16 deletions.
37 changes: 21 additions & 16 deletions cc-env_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,25 @@ const testProxyURL = "file:///proxyURL"
const testProxyVersion = "proxy version 0.1"
const testShimVersion = "shim version 0.1"

// makeVersionBinary creates a shell script with the specified file
// name. When run as "file --version", it will display the specified
// version to stdout and exit successfully.
func makeVersionBinary(file, version string) error {
err := createFile(file,
fmt.Sprintf(`#!/bin/sh
[ "$1" = "--version" ] && echo "%s"`, version))
if err != nil {
return err
}

err = os.Chmod(file, testExeFileMode)
if err != nil {
return err
}

return nil
}

func makeRuntimeConfig(prefixDir string) (configFile string, config oci.RuntimeConfig, err error) {
const logPath = "/log/path"
hypervisorPath := filepath.Join(prefixDir, "hypervisor")
Expand Down Expand Up @@ -75,26 +94,12 @@ func makeRuntimeConfig(prefixDir string) (configFile string, config oci.RuntimeC
}
}

err = createFile(shimPath,
fmt.Sprintf(`#!/bin/sh
[ "$1" = "--version" ] && echo "%s"`, testShimVersion))
if err != nil {
return "", oci.RuntimeConfig{}, err
}

err = os.Chmod(shimPath, testExeFileMode)
if err != nil {
return "", oci.RuntimeConfig{}, err
}

err = createFile(proxyPath,
fmt.Sprintf(`#!/bin/sh
[ "$1" = "--version" ] && echo "%s"`, testProxyVersion))
err = makeVersionBinary(shimPath, testShimVersion)
if err != nil {
return "", oci.RuntimeConfig{}, err
}

err = os.Chmod(proxyPath, testExeFileMode)
err = makeVersionBinary(proxyPath, testProxyVersion)
if err != nil {
return "", oci.RuntimeConfig{}, err
}
Expand Down

0 comments on commit 41abb89

Please sign in to comment.