From 2a8e435671186bead0e02b13f55e118724175cce Mon Sep 17 00:00:00 2001 From: Paul Holzinger Date: Fri, 22 Apr 2022 11:51:53 +0200 Subject: enable staticcheck linter Fix many problems reported by the staticcheck linter, including many real bugs! Signed-off-by: Paul Holzinger --- test/e2e/checkpoint_test.go | 2 +- test/e2e/common_test.go | 4 ++-- test/e2e/login_logout_test.go | 2 ++ test/e2e/push_test.go | 1 + test/e2e/systemd_activate_test.go | 2 +- test/utils/common_function_test.go | 3 +-- test/utils/utils.go | 2 +- test/version/main.go | 2 +- 8 files changed, 10 insertions(+), 8 deletions(-) (limited to 'test') diff --git a/test/e2e/checkpoint_test.go b/test/e2e/checkpoint_test.go index 7b2dd89c9..2dc99bdc9 100644 --- a/test/e2e/checkpoint_test.go +++ b/test/e2e/checkpoint_test.go @@ -1061,7 +1061,7 @@ var _ = Describe("Podman checkpoint", func() { // Open a network connection to the redis server via initial port mapping // This should fail - conn, err = net.DialTimeout("tcp4", fmt.Sprintf("localhost:%d", randomPort), time.Duration(3)*time.Second) + _, err = net.DialTimeout("tcp4", fmt.Sprintf("localhost:%d", randomPort), time.Duration(3)*time.Second) Expect(err).ToNot(BeNil()) Expect(err.Error()).To(ContainSubstring("connection refused")) // Open a network connection to the redis server via new port mapping diff --git a/test/e2e/common_test.go b/test/e2e/common_test.go index 2f4146bba..f808eb2b6 100644 --- a/test/e2e/common_test.go +++ b/test/e2e/common_test.go @@ -880,11 +880,11 @@ func (p *PodmanTestIntegration) makeOptions(args []string, noEvents, noCache boo func writeConf(conf []byte, confPath string) { if _, err := os.Stat(filepath.Dir(confPath)); os.IsNotExist(err) { - if err := os.MkdirAll(filepath.Dir(confPath), 777); err != nil { + if err := os.MkdirAll(filepath.Dir(confPath), 0o777); err != nil { fmt.Println(err) } } - if err := ioutil.WriteFile(confPath, conf, 777); err != nil { + if err := ioutil.WriteFile(confPath, conf, 0o777); err != nil { fmt.Println(err) } } diff --git a/test/e2e/login_logout_test.go b/test/e2e/login_logout_test.go index 77549a9a8..001779cdf 100644 --- a/test/e2e/login_logout_test.go +++ b/test/e2e/login_logout_test.go @@ -188,6 +188,8 @@ var _ = Describe("Podman login and logout", func() { Expect(session).To(ExitWithError()) session = podmanTest.Podman([]string{"logout", "--authfile", authFile, server}) + session.WaitWithDefaultTimeout() + Expect(session).Should(Exit(0)) }) It("podman login and logout with --tls-verify", func() { diff --git a/test/e2e/push_test.go b/test/e2e/push_test.go index a8a98fc07..3b571ab20 100644 --- a/test/e2e/push_test.go +++ b/test/e2e/push_test.go @@ -220,6 +220,7 @@ var _ = Describe("Podman push", func() { if setup.LineInOutputContains("Active: inactive") { setup = SystemExec("systemctl", []string{"start", "docker"}) + Expect(setup).Should(Exit(0)) defer func() { stop := SystemExec("systemctl", []string{"stop", "docker"}) Expect(stop).Should(Exit(0)) diff --git a/test/e2e/systemd_activate_test.go b/test/e2e/systemd_activate_test.go index d5434868d..04acafe1b 100644 --- a/test/e2e/systemd_activate_test.go +++ b/test/e2e/systemd_activate_test.go @@ -97,7 +97,7 @@ var _ = Describe("Systemd activate", func() { // Emulate 'systemd stop podman.service' activateSession.Signal(syscall.SIGTERM) - time.Sleep(2) + time.Sleep(100 * time.Millisecond) Eventually(activateSession).Should(Exit(0)) abiSession := podman("inspect", "--format={{.State.Running}}", containerName) diff --git a/test/utils/common_function_test.go b/test/utils/common_function_test.go index 6323b44eb..a73d75490 100644 --- a/test/utils/common_function_test.go +++ b/test/utils/common_function_test.go @@ -110,9 +110,8 @@ var _ = Describe("Common functions test", func() { Expect(err).To(BeNil(), "Failed to write JSON to file.") read, err := os.Open("/tmp/testJSON") - defer read.Close() - Expect(err).To(BeNil(), "Can not find the JSON file after we write it.") + defer read.Close() bytes, _ := ioutil.ReadAll(read) json.Unmarshal(bytes, compareData) diff --git a/test/utils/utils.go b/test/utils/utils.go index 39a0ac875..9695835e5 100644 --- a/test/utils/utils.go +++ b/test/utils/utils.go @@ -439,10 +439,10 @@ func tagOutputToMap(imagesOutput []string) map[string]map[string]bool { // GetHostDistributionInfo returns a struct with its distribution Name and version func GetHostDistributionInfo() HostOS { f, err := os.Open(OSReleasePath) - defer f.Close() if err != nil { return HostOS{} } + defer f.Close() l := bufio.NewScanner(f) host := HostOS{} diff --git a/test/version/main.go b/test/version/main.go index 8f2904405..2a68aa5fc 100644 --- a/test/version/main.go +++ b/test/version/main.go @@ -7,5 +7,5 @@ import ( ) func main() { - fmt.Printf(version.Version.String()) + fmt.Print(version.Version.String()) } -- cgit v1.2.3-54-g00ecf