summaryrefslogtreecommitdiff
path: root/test/utils
diff options
context:
space:
mode:
Diffstat (limited to 'test/utils')
-rw-r--r--test/utils/common_function_test.go12
-rw-r--r--test/utils/matchers.go8
-rw-r--r--test/utils/utils.go26
3 files changed, 19 insertions, 27 deletions
diff --git a/test/utils/common_function_test.go b/test/utils/common_function_test.go
index 003d490ce..c996a302c 100644
--- a/test/utils/common_function_test.go
+++ b/test/utils/common_function_test.go
@@ -90,24 +90,24 @@ var _ = Describe("Common functions test", func() {
Entry("Command exist", "Fakecmd", false),
)
- It("Test WriteJsonFile", func() {
- type testJson struct {
+ It("Test WriteJSONFile", func() {
+ type testJSON struct {
Item1 int
Item2 []string
}
- compareData := &testJson{}
+ compareData := &testJSON{}
- testData := &testJson{
+ testData := &testJSON{
Item1: 5,
Item2: []string{"test"},
}
testByte, _ := json.Marshal(testData)
- err := WriteJsonFile(testByte, "/tmp/testJson")
+ err := WriteJSONFile(testByte, "/tmp/testJSON")
Expect(err).To(BeNil(), "Failed to write JSON to file.")
- read, err := os.Open("/tmp/testJson")
+ read, err := os.Open("/tmp/testJSON")
defer read.Close()
Expect(err).To(BeNil(), "Can not find the JSON file after we write it.")
diff --git a/test/utils/matchers.go b/test/utils/matchers.go
index 17ff3ea75..69fb0cdfe 100644
--- a/test/utils/matchers.go
+++ b/test/utils/matchers.go
@@ -5,7 +5,7 @@ import (
"net/url"
"github.com/containers/common/pkg/config"
- . "github.com/onsi/gomega"
+ . "github.com/onsi/gomega" //nolint:golint,stylecheck
"github.com/onsi/gomega/format"
"github.com/onsi/gomega/gexec"
"github.com/onsi/gomega/matchers"
@@ -95,7 +95,7 @@ func (matcher *URLMatcher) Match(actual interface{}) (bool, error) {
if !ok {
return false, fmt.Errorf("VerifyURL requires string inputs %T is not supported", matcher.Expected)
}
- e_uri, err := url.Parse(e)
+ eURI, err := url.Parse(e)
if err != nil {
return false, err
}
@@ -104,12 +104,12 @@ func (matcher *URLMatcher) Match(actual interface{}) (bool, error) {
if !ok {
return false, fmt.Errorf("VerifyURL requires string inputs %T is not supported", actual)
}
- a_uri, err := url.Parse(a)
+ aURI, err := url.Parse(a)
if err != nil {
return false, err
}
- return (&matchers.EqualMatcher{Expected: e_uri}).Match(a_uri)
+ return (&matchers.EqualMatcher{Expected: eURI}).Match(aURI)
}
type ExitMatcher struct {
diff --git a/test/utils/utils.go b/test/utils/utils.go
index 4a57d9ce7..944c1ac3c 100644
--- a/test/utils/utils.go
+++ b/test/utils/utils.go
@@ -13,9 +13,9 @@ import (
"time"
"github.com/containers/storage/pkg/parsers/kernel"
- . "github.com/onsi/ginkgo"
- . "github.com/onsi/gomega"
- . "github.com/onsi/gomega/gexec"
+ . "github.com/onsi/ginkgo" //nolint:golint,stylecheck
+ . "github.com/onsi/gomega" //nolint:golint,stylecheck
+ . "github.com/onsi/gomega/gexec" //nolint:golint,stylecheck
)
var (
@@ -439,25 +439,21 @@ func IsKernelNewerThan(version string) (bool, error) {
return true, nil
}
return false, nil
-
}
// IsCommandAvailable check if command exist
func IsCommandAvailable(command string) bool {
check := exec.Command("bash", "-c", strings.Join([]string{"command -v", command}, " "))
err := check.Run()
- if err != nil {
- return false
- }
- return true
+ return err == nil
}
-// WriteJsonFile write json format data to a json file
-func WriteJsonFile(data []byte, filePath string) error {
+// WriteJSONFile write json format data to a json file
+func WriteJSONFile(data []byte, filePath string) error {
var jsonData map[string]interface{}
json.Unmarshal(data, &jsonData)
- formatJson, _ := json.MarshalIndent(jsonData, "", " ")
- return ioutil.WriteFile(filePath, formatJson, 0644)
+ formatJSON, _ := json.MarshalIndent(jsonData, "", " ")
+ return ioutil.WriteFile(filePath, formatJSON, 0644)
}
// Containerized check the podman command run inside container
@@ -471,10 +467,7 @@ func Containerized() bool {
// shrug, if we cannot read that file, return false
return false
}
- if strings.Index(string(b), "docker") > -1 {
- return true
- }
- return false
+ return strings.Contains(string(b), "docker")
}
func init() {
@@ -485,7 +478,6 @@ var randomLetters = []rune("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ
// RandomString returns a string of given length composed of random characters
func RandomString(n int) string {
-
b := make([]rune, n)
for i := range b {
b[i] = randomLetters[rand.Intn(len(randomLetters))]