Skip to content

Commit

Permalink
Add go workflow to lint src/bpm/ (#164)
Browse files Browse the repository at this point in the history
* Add go workflow to lint src/bpm/

* Fix lint errors or add nolint comments
  • Loading branch information
aramprice authored Feb 29, 2024
1 parent d384f52 commit b5ea657
Show file tree
Hide file tree
Showing 37 changed files with 112 additions and 112 deletions.
15 changes: 15 additions & 0 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
name: go
on:
push:
pull_request:
jobs:
lint:
runs-on: [ubuntu-latest]
steps:
- uses: actions/checkout@v3
- uses: actions/setup-go@v4
with:
go-version-file: src/bpm/go.mod
- uses: golangci/golangci-lint-action@v3
with:
working-directory: src/bpm/
7 changes: 7 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# https://golangci-lint.run/usage/configuration/
run:
timeout: 5m # 1m default times out on github-action runners

output:
# Sort results by: filepath, line and column.
sort-results: true
28 changes: 14 additions & 14 deletions src/bpm/acceptance/bpm_acceptance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ package bpm_acceptance_test
import (
"bufio"
"fmt"
"io/ioutil"
"io"
"net/http"
"sort"
"strings"
Expand All @@ -41,7 +41,7 @@ var _ = Describe("BpmAcceptance", func() {

Expect(resp.StatusCode).To(Equal(http.StatusOK))

body, err := ioutil.ReadAll(resp.Body)
body, err := io.ReadAll(resp.Body)
Expect(err).NotTo(HaveOccurred())
Expect(string(body)).To(Equal("BPM is SWEET!\n"))
})
Expand All @@ -51,7 +51,7 @@ var _ = Describe("BpmAcceptance", func() {
Expect(err).NotTo(HaveOccurred())
defer resp.Body.Close()

body, err := ioutil.ReadAll(resp.Body)
body, err := io.ReadAll(resp.Body)
Expect(err).NotTo(HaveOccurred())
Expect(string(body)).To(Equal("vcap\n"))
})
Expand All @@ -61,7 +61,7 @@ var _ = Describe("BpmAcceptance", func() {
Expect(err).NotTo(HaveOccurred())
defer resp.Body.Close()

body, err := ioutil.ReadAll(resp.Body)
body, err := io.ReadAll(resp.Body)
Expect(err).NotTo(HaveOccurred())

mounts := parseMounts(string(body))
Expand Down Expand Up @@ -108,7 +108,7 @@ var _ = Describe("BpmAcceptance", func() {
Expect(err).NotTo(HaveOccurred())
defer resp.Body.Close()

body, err := ioutil.ReadAll(resp.Body)
body, err := io.ReadAll(resp.Body)
Expect(err).NotTo(HaveOccurred())

mounts := parseMounts(string(body))
Expand All @@ -130,7 +130,7 @@ var _ = Describe("BpmAcceptance", func() {
Expect(err).NotTo(HaveOccurred())
defer resp.Body.Close()

body, err := ioutil.ReadAll(resp.Body)
body, err := io.ReadAll(resp.Body)
Expect(err).NotTo(HaveOccurred())

Expect(string(body)).To(Equal(""))
Expand All @@ -141,7 +141,7 @@ var _ = Describe("BpmAcceptance", func() {
Expect(err).NotTo(HaveOccurred())
defer resp.Body.Close()

body, err := ioutil.ReadAll(resp.Body)
body, err := io.ReadAll(resp.Body)
Expect(err).NotTo(HaveOccurred())
directories := strings.Split(strings.Trim(string(body), "\n"), "\n")
Expect(directories).To(ConsistOf("store", "data", "jobs", "packages", "sys"))
Expand All @@ -152,7 +152,7 @@ var _ = Describe("BpmAcceptance", func() {
Expect(err).NotTo(HaveOccurred())
defer resp.Body.Close()

body, err := ioutil.ReadAll(resp.Body)
body, err := io.ReadAll(resp.Body)
Expect(err).NotTo(HaveOccurred())
directories := strings.Split(strings.Trim(string(body), "\n"), "\n")
Expect(directories).To(ConsistOf("test-server", "packages", "shared"))
Expand All @@ -163,7 +163,7 @@ var _ = Describe("BpmAcceptance", func() {
Expect(err).NotTo(HaveOccurred())
defer resp.Body.Close()

body, err := ioutil.ReadAll(resp.Body)
body, err := io.ReadAll(resp.Body)
Expect(err).NotTo(HaveOccurred())
directories := strings.Split(strings.Trim(string(body), "\n"), "\n")
Expect(directories).To(ConsistOf("test-server"))
Expand All @@ -174,7 +174,7 @@ var _ = Describe("BpmAcceptance", func() {
Expect(err).NotTo(HaveOccurred())
defer resp.Body.Close()

body, err := ioutil.ReadAll(resp.Body)
body, err := io.ReadAll(resp.Body)
Expect(err).NotTo(HaveOccurred())
processes := strings.Split(strings.Trim(string(body), "\n"), "\n")

Expand All @@ -191,7 +191,7 @@ var _ = Describe("BpmAcceptance", func() {
Expect(err).NotTo(HaveOccurred())
defer resp.Body.Close()

body, err := ioutil.ReadAll(resp.Body)
body, err := io.ReadAll(resp.Body)
Expect(err).NotTo(HaveOccurred())
Expect(string(body)).To(ContainSubstring("/var/vcap/jobs/test-server/bin:/usr/local/bin:/usr/local/sbin:/usr/bin:/usr/sbin:/bin:/sbin:."))
})
Expand All @@ -204,7 +204,7 @@ var _ = Describe("BpmAcceptance", func() {
Expect(err).NotTo(HaveOccurred())
defer resp.Body.Close()

body, err := ioutil.ReadAll(resp.Body)
body, err := io.ReadAll(resp.Body)
Expect(err).NotTo(HaveOccurred())
Expect(string(body)).To(ContainSubstring("/var/vcap/data/"))
})
Expand All @@ -217,7 +217,7 @@ var _ = Describe("BpmAcceptance", func() {

Expect(resp.StatusCode).To(Equal(http.StatusOK))

body, err := ioutil.ReadAll(resp.Body)
body, err := io.ReadAll(resp.Body)
Expect(err).NotTo(HaveOccurred())
Expect(string(body)).To(ContainSubstring("Expected success occurred"))
})
Expand All @@ -229,7 +229,7 @@ var _ = Describe("BpmAcceptance", func() {

Expect(resp.StatusCode).To(Equal(http.StatusOK))

body, err := ioutil.ReadAll(resp.Body)
body, err := io.ReadAll(resp.Body)
Expect(err).NotTo(HaveOccurred())
Expect(string(body)).To(ContainSubstring("Expected error occurred"))
})
Expand Down
3 changes: 1 addition & 2 deletions src/bpm/acceptance/fixtures/test-server/handlers/curl.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,11 @@ package handlers

import (
"io"
"io/ioutil"
"net/http"
)

func Curl(w http.ResponseWriter, r *http.Request) {
address, err := ioutil.ReadAll(r.Body)
address, err := io.ReadAll(r.Body)
if err != nil {
w.WriteHeader(http.StatusInternalServerError)
return
Expand Down
4 changes: 2 additions & 2 deletions src/bpm/acceptance/fixtures/test-server/handlers/env.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@ package handlers

import (
"fmt"
"io/ioutil"
"io"
"net/http"
"os"
)

func Env(w http.ResponseWriter, r *http.Request) {
envKey, err := ioutil.ReadAll(r.Body)
envKey, err := io.ReadAll(r.Body)
if err != nil {
w.WriteHeader(http.StatusInternalServerError)
return
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ func MaskedPaths(w http.ResponseWriter, r *http.Request) {
} else {
cmd := exec.Command("/bin/dd", fmt.Sprintf("if=%s", path))
output, err := cmd.CombinedOutput()
defer cmd.Process.Kill() // as dd could run indefinitely and cause issues with other tests...
// as dd could run indefinitely and cause issues with other tests...
defer cmd.Process.Kill() //nolint:errcheck

if err != nil {
readablePaths += fmt.Sprintf("Error reading path: %s\n", path)
Expand Down
4 changes: 2 additions & 2 deletions src/bpm/acceptance/fixtures/test-server/handlers/mounts.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@ package handlers

import (
"fmt"
"io/ioutil"
"net/http"
"os"
)

func Mounts(w http.ResponseWriter, r *http.Request) {
data, err := ioutil.ReadFile("/proc/mounts")
data, err := os.ReadFile("/proc/mounts")
if err != nil {
w.WriteHeader(http.StatusInternalServerError)
return
Expand Down
6 changes: 3 additions & 3 deletions src/bpm/acceptance/fixtures/test-server/handlers/processes.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ package handlers

import (
"fmt"
"io/ioutil"
"net/http"
"os"
"path/filepath"
)

Expand All @@ -30,12 +30,12 @@ func Processes(w http.ResponseWriter, r *http.Request) {
}

for _, item := range items {
body, err := ioutil.ReadFile(filepath.Join(item, "cmdline"))
body, err := os.ReadFile(filepath.Join(item, "cmdline"))
if err != nil {
w.WriteHeader(http.StatusInternalServerError)
return
}

fmt.Fprintln(w, fmt.Sprintf("%s %s", filepath.Base(item), string(body)))
fmt.Fprintf(w, "%s %s\n", filepath.Base(item), string(body))
}
}
8 changes: 4 additions & 4 deletions src/bpm/acceptance/fixtures/test-server/handlers/varvcap.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@ package handlers

import (
"fmt"
"io/ioutil"
"net/http"
"os"
)

func VarVcap(w http.ResponseWriter, r *http.Request) {
items, err := ioutil.ReadDir("/var/vcap")
items, err := os.ReadDir("/var/vcap")
if err != nil {
w.WriteHeader(http.StatusInternalServerError)
return
Expand All @@ -34,7 +34,7 @@ func VarVcap(w http.ResponseWriter, r *http.Request) {
}

func VarVcapJobs(w http.ResponseWriter, r *http.Request) {
items, err := ioutil.ReadDir("/var/vcap/jobs")
items, err := os.ReadDir("/var/vcap/jobs")
if err != nil {
w.WriteHeader(http.StatusInternalServerError)
return
Expand All @@ -46,7 +46,7 @@ func VarVcapJobs(w http.ResponseWriter, r *http.Request) {
}

func VarVcapData(w http.ResponseWriter, r *http.Request) {
items, err := ioutil.ReadDir("/var/vcap/data")
items, err := os.ReadDir("/var/vcap/data")
if err != nil {
w.WriteHeader(http.StatusInternalServerError)
return
Expand Down
4 changes: 2 additions & 2 deletions src/bpm/bosh/env.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
package bosh

import (
"io/ioutil"
"os"
"path/filepath"
)

Expand All @@ -43,7 +43,7 @@ func NewEnv(root string) *Env {
func (e *Env) JobNames() []string {
var jobs []string

fileInfos, err := ioutil.ReadDir(filepath.Join(e.root, "jobs"))
fileInfos, err := os.ReadDir(filepath.Join(e.root, "jobs"))
if err != nil {
return jobs
}
Expand Down
3 changes: 1 addition & 2 deletions src/bpm/bosh/env_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
package bosh_test

import (
"io/ioutil"
"os"
"path/filepath"

Expand All @@ -31,7 +30,7 @@ var _ = Describe("Bosh Environment", func() {

BeforeEach(func() {
var err error
root, err = ioutil.TempDir("", "bosh_test")
root, err = os.MkdirTemp("", "bosh_test")
Expect(err).NotTo(HaveOccurred())
})

Expand Down
2 changes: 1 addition & 1 deletion src/bpm/commands/logs.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ func logsForJob(cmd *cobra.Command, _ []string) error {
for {
select {
case sig := <-signals: // Forward signal received by parent to child
tailCmd.Process.Signal(sig)
tailCmd.Process.Signal(sig) //nolint:errcheck
case err := <-errCh: // Signal parent when child dies
if err != nil && err.Error() != "signal: interrupt" {
return err
Expand Down
2 changes: 1 addition & 1 deletion src/bpm/commands/trace.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ func trace(cmd *cobra.Command, _ []string) error {
for {
select {
case sig := <-signals:
straceCmd.Process.Signal(sig)
straceCmd.Process.Signal(sig) //nolint:errcheck
case err := <-errCh:
if eerr, ok := err.(*exec.ExitError); ok {
// was the process killed by a signal?
Expand Down
2 changes: 1 addition & 1 deletion src/bpm/commands/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ var versionCommand = &cobra.Command{

func version(cmd *cobra.Command, args []string) {
if len(args) != 0 {
cmd.Usage()
cmd.Usage() //nolint:errcheck
os.Exit(1)
}

Expand Down
4 changes: 2 additions & 2 deletions src/bpm/config/job_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ package config
import (
"errors"
"fmt"
"io/ioutil"
"os"
"path/filepath"
"strings"

Expand Down Expand Up @@ -73,7 +73,7 @@ type Unsafe struct {
}

func ParseJobConfig(configPath string) (*JobConfig, error) {
data, err := ioutil.ReadFile(configPath)
data, err := os.ReadFile(configPath)
if err != nil {
return nil, err
}
Expand Down
7 changes: 3 additions & 4 deletions src/bpm/flock/flock_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
package flock_test

import (
"io/ioutil"
"os"
"path/filepath"

Expand All @@ -31,7 +30,7 @@ var _ = Describe("Flock", func() {

BeforeEach(func() {
var err error
tmpdir, err = ioutil.TempDir("", "flocktest")
tmpdir, err = os.MkdirTemp("", "flocktest")
Expect(err).NotTo(HaveOccurred())
})

Expand All @@ -56,7 +55,7 @@ var _ = Describe("Flock", func() {

It("cannot be unlocked again", func() {
Expect(func() {
lock.Unlock()
lock.Unlock() //nolint:errcheck
}).Should(Panic())
})

Expand All @@ -76,7 +75,7 @@ var _ = Describe("Flock", func() {
Expect(err).NotTo(HaveOccurred())

Expect(func() {
lock.Unlock()
lock.Unlock() //nolint:errcheck
}).Should(Panic())
})

Expand Down
3 changes: 1 addition & 2 deletions src/bpm/hostlock/hostlock_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
package hostlock_test

import (
"io/ioutil"
"os"

. "github.com/onsi/ginkgo"
Expand All @@ -30,7 +29,7 @@ var _ = Describe("Hostlock", func() {

BeforeEach(func() {
var err error
tmpdir, err = ioutil.TempDir("", "hostlock_test")
tmpdir, err = os.MkdirTemp("", "hostlock_test")
Expect(err).NotTo(HaveOccurred())
})

Expand Down
Loading

0 comments on commit b5ea657

Please sign in to comment.