diff options
author | Paul Holzinger <pholzing@redhat.com> | 2022-04-25 15:15:52 +0200 |
---|---|---|
committer | Paul Holzinger <pholzing@redhat.com> | 2022-04-26 18:12:22 +0200 |
commit | 51fbf3da9ee34a8143df5baeda6032c1747446d2 (patch) | |
tree | f5edbd047f5e4aea72b710403a0aa208b238c83b /pkg/bindings | |
parent | 216d9243077f478a9c7ffda1c6e0b1fcbad9ee76 (diff) | |
download | podman-51fbf3da9ee34a8143df5baeda6032c1747446d2.tar.gz podman-51fbf3da9ee34a8143df5baeda6032c1747446d2.tar.bz2 podman-51fbf3da9ee34a8143df5baeda6032c1747446d2.zip |
enable gocritic linter
The linter ensures a common code style.
- use switch/case instead of else if
- use if instead of switch/case for single case statement
- add space between comment and text
- detect the use of defer with os.Exit()
- use short form var += "..." instead of var = var + "..."
- detect problems with append()
```
newSlice := append(orgSlice, val)
```
This could lead to nasty bugs because the orgSlice will be changed in
place if it has enough capacity too hold the new elements. Thus we
newSlice might not be a copy.
Of course most of the changes are just cosmetic and do not cause any
logic errors but I think it is a good idea to enforce a common style.
This should help maintainability.
Signed-off-by: Paul Holzinger <pholzing@redhat.com>
Diffstat (limited to 'pkg/bindings')
-rw-r--r-- | pkg/bindings/images/build.go | 16 | ||||
-rw-r--r-- | pkg/bindings/images/types.go | 2 | ||||
-rw-r--r-- | pkg/bindings/network/network.go | 4 | ||||
-rw-r--r-- | pkg/bindings/test/containers_test.go | 34 | ||||
-rw-r--r-- | pkg/bindings/test/pods_test.go | 6 | ||||
-rw-r--r-- | pkg/bindings/test/volumes_test.go | 13 |
6 files changed, 30 insertions, 45 deletions
diff --git a/pkg/bindings/images/build.go b/pkg/bindings/images/build.go index 1729bd922..9e0a0d798 100644 --- a/pkg/bindings/images/build.go +++ b/pkg/bindings/images/build.go @@ -225,10 +225,8 @@ func Build(ctx context.Context, containerFiles []string, options entities.BuildO platform = "linux" } platform += "/" + options.Architecture - } else { - if len(platform) > 0 { - platform += "/" + runtime.GOARCH - } + } else if len(platform) > 0 { + platform += "/" + runtime.GOARCH } if len(platform) > 0 { params.Set("platform", platform) @@ -447,7 +445,7 @@ func Build(ctx context.Context, containerFiles []string, options entities.BuildO } } } - secretsForRemote = append(secretsForRemote, strings.Join(modifiedOpt[:], ",")) + secretsForRemote = append(secretsForRemote, strings.Join(modifiedOpt, ",")) } } @@ -603,8 +601,8 @@ func nTar(excludes []string, sources ...string) (io.ReadCloser, error) { // are required to visit all files. :( return nil } - - if d.Type().IsRegular() { // add file item + switch { + case d.Type().IsRegular(): // add file item info, err := d.Info() if err != nil { return err @@ -644,7 +642,7 @@ func nTar(excludes []string, sources ...string) (io.ReadCloser, error) { seen[di] = name } return err - } else if d.IsDir() { // add folders + case d.IsDir(): // add folders info, err := d.Info() if err != nil { return err @@ -658,7 +656,7 @@ func nTar(excludes []string, sources ...string) (io.ReadCloser, error) { if lerr := tw.WriteHeader(hdr); lerr != nil { return lerr } - } else if d.Type()&os.ModeSymlink != 0 { // add symlinks as it, not content + case d.Type()&os.ModeSymlink != 0: // add symlinks as it, not content link, err := os.Readlink(path) if err != nil { return err diff --git a/pkg/bindings/images/types.go b/pkg/bindings/images/types.go index 75cb38a0a..8e5e7ee92 100644 --- a/pkg/bindings/images/types.go +++ b/pkg/bindings/images/types.go @@ -177,7 +177,7 @@ type PullOptions struct { Variant *string } -//BuildOptions are optional options for building images +// BuildOptions are optional options for building images type BuildOptions struct { buildahDefine.BuildOptions } diff --git a/pkg/bindings/network/network.go b/pkg/bindings/network/network.go index 6c7777fdd..83641f677 100644 --- a/pkg/bindings/network/network.go +++ b/pkg/bindings/network/network.go @@ -101,7 +101,7 @@ func List(ctx context.Context, options *ListOptions) ([]types.Network, error) { } // Disconnect removes a container from a given network -func Disconnect(ctx context.Context, networkName string, ContainerNameOrID string, options *DisconnectOptions) error { +func Disconnect(ctx context.Context, networkName string, containerNameOrID string, options *DisconnectOptions) error { if options == nil { options = new(DisconnectOptions) } @@ -114,7 +114,7 @@ func Disconnect(ctx context.Context, networkName string, ContainerNameOrID strin Container string Force bool }{ - Container: ContainerNameOrID, + Container: containerNameOrID, } if force := options.GetForce(); options.Changed("Force") { disconnect.Force = force diff --git a/pkg/bindings/test/containers_test.go b/pkg/bindings/test/containers_test.go index bf627fdba..090dd294c 100644 --- a/pkg/bindings/test/containers_test.go +++ b/pkg/bindings/test/containers_test.go @@ -104,9 +104,9 @@ var _ = Describe("Podman containers ", func() { // Pause by name err = containers.Pause(bt.conn, name, nil) Expect(err).To(BeNil(), "error from containers.Pause()") - //paused := "paused" - //_, err = containers.Wait(bt.conn, cid, &paused) - //Expect(err).To(BeNil()) + // paused := "paused" + // _, err = containers.Wait(bt.conn, cid, &paused) + // Expect(err).To(BeNil()) err = containers.Unpause(bt.conn, name, nil) Expect(err).To(BeNil()) @@ -332,8 +332,8 @@ var _ = Describe("Podman containers ", func() { // TODO for the life of me, i cannot get this to work. maybe another set // of eyes will // successful healthcheck - //status := define.HealthCheckHealthy - //for i:=0; i < 10; i++ { + // status := define.HealthCheckHealthy + // for i:=0; i < 10; i++ { // result, err := containers.RunHealthCheck(connText, "hc") // Expect(err).To(BeNil()) // if result.Status != define.HealthCheckHealthy { @@ -343,18 +343,18 @@ var _ = Describe("Podman containers ", func() { // } // status = result.Status // break - //} - //Expect(status).To(Equal(define.HealthCheckHealthy)) + // } + // Expect(status).To(Equal(define.HealthCheckHealthy)) // TODO enable this when wait is working // healthcheck on a stopped container should be a 409 - //err = containers.Stop(connText, "hc", nil) - //Expect(err).To(BeNil()) - //_, err = containers.Wait(connText, "hc") - //Expect(err).To(BeNil()) - //_, err = containers.RunHealthCheck(connText, "hc") - //code, _ = bindings.CheckResponseCode(err) - //Expect(code).To(BeNumerically("==", http.StatusConflict)) + // err = containers.Stop(connText, "hc", nil) + // Expect(err).To(BeNil()) + // _, err = containers.Wait(connText, "hc") + // Expect(err).To(BeNil()) + // _, err = containers.RunHealthCheck(connText, "hc") + // code, _ = bindings.CheckResponseCode(err) + // Expect(code).To(BeNumerically("==", http.StatusConflict)) }) It("logging", func() { @@ -490,7 +490,7 @@ var _ = Describe("Podman containers ", func() { }) It("podman kill a running container by bogus signal", func() { - //Killing a running container by bogus signal should fail + // Killing a running container by bogus signal should fail var name = "top" cid, err := bt.RunTopContainer(&name, nil) Expect(err).To(BeNil()) @@ -580,7 +580,7 @@ var _ = Describe("Podman containers ", func() { // Valid filter params container should be pruned now. filters := map[string][]string{ - "until": {"5000000000"}, //Friday, June 11, 2128 + "until": {"5000000000"}, // Friday, June 11, 2128 } pruneResponse, err = containers.Prune(bt.conn, new(containers.PruneOptions).WithFilters(filters)) Expect(err).To(BeNil()) @@ -594,7 +594,7 @@ var _ = Describe("Podman containers ", func() { Expect(err).To(BeNil()) filters := map[string][]string{ - "until": {"5000000000"}, //Friday, June 11, 2128 + "until": {"5000000000"}, // Friday, June 11, 2128 } c, err := containers.List(bt.conn, new(containers.ListOptions).WithFilters(filters).WithAll(true)) Expect(err).To(BeNil()) diff --git a/pkg/bindings/test/pods_test.go b/pkg/bindings/test/pods_test.go index 1c93c5595..d47e9ee0e 100644 --- a/pkg/bindings/test/pods_test.go +++ b/pkg/bindings/test/pods_test.go @@ -43,13 +43,13 @@ var _ = Describe("Podman pods", func() { }) It("inspect pod", func() { - //Inspect an invalid pod name + // Inspect an invalid pod name _, err := pods.Inspect(bt.conn, "dummyname", nil) Expect(err).ToNot(BeNil()) code, _ := bindings.CheckResponseCode(err) Expect(code).To(BeNumerically("==", http.StatusNotFound)) - //Inspect an valid pod name + // Inspect an valid pod name response, err := pods.Inspect(bt.conn, newpod, nil) Expect(err).To(BeNil()) Expect(response.Name).To(Equal(newpod)) @@ -57,7 +57,7 @@ var _ = Describe("Podman pods", func() { // Test validates the list all api returns It("list pod", func() { - //List all the pods in the current instance + // List all the pods in the current instance podSummary, err := pods.List(bt.conn, nil) Expect(err).To(BeNil()) Expect(len(podSummary)).To(Equal(1)) diff --git a/pkg/bindings/test/volumes_test.go b/pkg/bindings/test/volumes_test.go index c0d01439b..8ae93eed9 100644 --- a/pkg/bindings/test/volumes_test.go +++ b/pkg/bindings/test/volumes_test.go @@ -18,9 +18,6 @@ import ( var _ = Describe("Podman volumes", func() { var ( - //tempdir string - //err error - //podmanTest *PodmanTestIntegration bt *bindingTest s *gexec.Session connText context.Context @@ -28,13 +25,6 @@ var _ = Describe("Podman volumes", func() { ) BeforeEach(func() { - //tempdir, err = CreateTempDirInTempDir() - //if err != nil { - // os.Exit(1) - //} - //podmanTest = PodmanTestCreate(tempdir) - //podmanTest.Setup() - //podmanTest.SeedImages() bt = newBindingTest() bt.RestoreImagesFromCache() s = bt.startAPIService() @@ -44,9 +34,6 @@ var _ = Describe("Podman volumes", func() { }) AfterEach(func() { - //podmanTest.Cleanup() - //f := CurrentGinkgoTestDescription() - //processTestResult(f) s.Kill() bt.cleanup() }) |