Skip to content

Commit

Permalink
fix linting issues
Browse files Browse the repository at this point in the history
  • Loading branch information
shaynafinocchiaro committed Feb 21, 2024
1 parent 2edf045 commit dd55a30
Show file tree
Hide file tree
Showing 30 changed files with 231 additions and 233 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/actions.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
- name: Checkout the code
uses: actions/checkout@v4
- name: Run the formatter, linter, and vetter
uses: dell/common-github-actions/go-code-formatter-linter-vetter@main
uses: dell/common-github-actions/go-code-formatter-linter-vetter@update-golint
with:
directories: ./...
sanitize:
Expand Down
2 changes: 0 additions & 2 deletions .golangci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@ linters:
enable:
# A stricter replacement for gofmt.
- gofumpt
# Inspects source code for security problems.
- gosec
# Check for correctness of programs.
- govet
# Drop-in replacement of golint.
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -138,4 +138,4 @@ download-csm-common:

.PHONY: lint
lint:
golangci-lint run --fix
golangci-lint run --fix
8 changes: 4 additions & 4 deletions cmd/proxy-server/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ func run(log *logrus.Entry) error {
JWTSigningSecret = cfg.Web.JWTSigningSecret

cfgViper.WatchConfig()
cfgViper.OnConfigChange(func(e fsnotify.Event) {
cfgViper.OnConfigChange(func(_ fsnotify.Event) {
updateConfiguration(cfgViper, log)
})

Expand Down Expand Up @@ -218,7 +218,7 @@ func run(log *logrus.Entry) error {
updateLoggingSettings(log)

csmViper.WatchConfig()
csmViper.OnConfigChange(func(e fsnotify.Event) {
csmViper.OnConfigChange(func(_ fsnotify.Event) {
updateLoggingSettings(log)
})

Expand Down Expand Up @@ -385,7 +385,7 @@ func run(log *logrus.Entry) error {
web.LoggingMW(log, cfg.Web.ShowDebugHTTP), // log all requests
web.CleanMW(), // clean paths
web.OtelMW(tp, "", // format the span name
otelhttp.WithSpanNameFormatter(func(s string, r *http.Request) string {
otelhttp.WithSpanNameFormatter(func(_ string, r *http.Request) string {
return fmt.Sprintf("%s %s", r.Method, r.URL.Path)
}))),
ReadTimeout: cfg.Proxy.ReadTimeout,
Expand Down Expand Up @@ -595,7 +595,7 @@ func refreshAdminTokenHandler(log *logrus.Entry) http.Handler {

func rolesHandler(log *logrus.Entry, opaHost string) http.Handler {
url := fmt.Sprintf("http://%s/v1/data/karavi/common/roles", opaHost)
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
return http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
req, err := http.NewRequest(http.MethodGet, url, nil)
if err != nil {
log.WithError(err).Fatal()
Expand Down
10 changes: 5 additions & 5 deletions cmd/proxy-server/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ func TestVolumesHandler(t *testing.T) {
err = rff.Add(roleInstance)
checkError(t, err)

getRolesFn := func(ctx context.Context) (*roles.JSON, error) {
getRolesFn := func(_ context.Context) (*roles.JSON, error) {
return &rff, nil
}
roleSvc := role.NewService(fakeRoleKube{GetConfiguredRolesFn: getRolesFn}, successfulRoleValidator{})
Expand Down Expand Up @@ -269,7 +269,7 @@ func TestVolumesHandler(t *testing.T) {
err = rff.Add(roleInstanceTwo)
checkError(t, err)

getRolesFn := func(ctx context.Context) (*roles.JSON, error) {
getRolesFn := func(_ context.Context) (*roles.JSON, error) {
return &rff, nil
}
rolesSvc := role.NewService(fakeRoleKube{GetConfiguredRolesFn: getRolesFn}, successfulRoleValidator{})
Expand Down Expand Up @@ -353,7 +353,7 @@ func TestVolumesHandler(t *testing.T) {
// create No Roles
rff := roles.NewJSON()

getRolesFn := func(ctx context.Context) (*roles.JSON, error) {
getRolesFn := func(_ context.Context) (*roles.JSON, error) {
return &rff, nil
}
roleSvc := role.NewService(fakeRoleKube{GetConfiguredRolesFn: getRolesFn}, successfulRoleValidator{})
Expand Down Expand Up @@ -432,7 +432,7 @@ func TestVolumesHandler(t *testing.T) {
err = rff.Add(roleInstanceTwo)
checkError(t, err)

getRolesFn := func(ctx context.Context) (*roles.JSON, error) {
getRolesFn := func(_ context.Context) (*roles.JSON, error) {
return &rff, nil
}
roleSvc := role.NewService(fakeRoleKube{GetConfiguredRolesFn: getRolesFn}, successfulRoleValidator{})
Expand Down Expand Up @@ -528,7 +528,7 @@ func TestVolumesHandler(t *testing.T) {
err = rff.Add(roleInstanceTwo)
checkError(t, err)

getRolesFn := func(ctx context.Context) (*roles.JSON, error) {
getRolesFn := func(_ context.Context) (*roles.JSON, error) {
return &rff, nil
}
roleSvc := role.NewService(fakeRoleKube{GetConfiguredRolesFn: getRolesFn}, successfulRoleValidator{})
Expand Down
2 changes: 1 addition & 1 deletion cmd/storage-service/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ func main() {
updateConcurrentPowerFlexRequests(storageSvc, log)

csmViper.WatchConfig()
csmViper.OnConfigChange(func(e fsnotify.Event) {
csmViper.OnConfigChange(func(_ fsnotify.Event) {
updateLoggingSettings(log)
updateConcurrentPowerFlexRequests(storageSvc, log)
})
Expand Down
4 changes: 2 additions & 2 deletions cmd/tenant-service/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ func main() {
}

cfgViper.WatchConfig()
cfgViper.OnConfigChange(func(e fsnotify.Event) {
cfgViper.OnConfigChange(func(_ fsnotify.Event) {
updateConfiguration(cfgViper, log)
})

Expand Down Expand Up @@ -136,7 +136,7 @@ func main() {
updateLoggingSettings(log)

csmViper.WatchConfig()
csmViper.OnConfigChange(func(e fsnotify.Event) {
csmViper.OnConfigChange(func(_ fsnotify.Event) {
log.Info("csm-config-params changed!")
updateLoggingSettings(log)
})
Expand Down
8 changes: 4 additions & 4 deletions deploy/install_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,7 @@ func TestDeployProcess_ChownK3sKubeConfig(t *testing.T) {
})
t.Run("it handles failure to chown the kubeconfig", func(t *testing.T) {
err := errors.New("test error")
osChown = func(_ string, uid, gid int) error {
osChown = func(_ string, _, _ int) error {
return err
}
sut.processOwnerUID = 1000
Expand Down Expand Up @@ -803,7 +803,7 @@ func TestDeployProcess_InstallK3s(t *testing.T) {
osChmod = func(_ string, _ fs.FileMode) error {
return nil
}
osOpenFile = func(name string, flag int, perm os.FileMode) (*os.File, error) {
osOpenFile = func(name string, _ int, _ os.FileMode) (*os.File, error) {
var err error
// openedFile, err = os.Create(filepath.Join(os.TempDir(), filepath.Base(name)))
openedFile, err = ioutil.TempFile(os.TempDir(), "")
Expand All @@ -830,7 +830,7 @@ func TestDeployProcess_InstallK3s(t *testing.T) {
defer afterEach()
sut.Err = nil
givenErr := errors.New("test error")
osCreate = func(name string) (*os.File, error) {
osCreate = func(_ string) (*os.File, error) {
return nil, givenErr
}

Expand Down Expand Up @@ -870,7 +870,7 @@ func TestDeployProcess_InstallK3s(t *testing.T) {
return createdFile, nil
}

osOpenFile = func(name string, flag int, perm os.FileMode) (*os.File, error) {
osOpenFile = func(_ string, _ int, _ os.FileMode) (*os.File, error) {
var err error
// openedFile, err = os.Create(filepath.Join(os.TempDir(), filepath.Base(name)))
openedFile, err = ioutil.TempFile(os.TempDir(), "")
Expand Down
14 changes: 7 additions & 7 deletions internal/k8s/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ func TestGetConfiguredRoles(t *testing.T) {
}

hasErr := func() func(*testing.T, *roles.JSON, error) {
return func(t *testing.T, j *roles.JSON, err error) {
return func(t *testing.T, _ *roles.JSON, err error) {
if err == nil {
t.Errorf("expected nil err, got %+v", err)
}
Expand Down Expand Up @@ -115,7 +115,7 @@ roles = {
return connect, nil, checkExpectedOutput(key, &expectedRoles)
},
"error connecting": func(*testing.T) (connectFn, configFn, checkFn) {
connect := func(api *API) error {
connect := func(_ *API) error {
return errors.New("error")
}
return connect, nil, hasErr()
Expand Down Expand Up @@ -264,15 +264,15 @@ func TestGetConfiguredStorage(t *testing.T) {
type checkFn func(*testing.T, storage.Storage, error)

checkExpectedOutput := func(want storage.Storage) func(*testing.T, storage.Storage, error) {
return func(t *testing.T, got storage.Storage, err error) {
return func(t *testing.T, got storage.Storage, _ error) {
if !reflect.DeepEqual(want, got) {
t.Errorf("want %+v, got %+v", want, got)
}
}
}

hasErr := func() func(*testing.T, storage.Storage, error) {
return func(t *testing.T, got storage.Storage, err error) {
return func(t *testing.T, _ storage.Storage, err error) {
if err == nil {
t.Errorf("expected nil err, got %+v", err)
}
Expand Down Expand Up @@ -321,7 +321,7 @@ storage:
return connect, nil, checkExpectedOutput(expectedStorage)
},
"error connecting": func(*testing.T) (connectFn, configFn, checkFn) {
connect := func(api *API) error {
connect := func(_ *API) error {
return errors.New("error")
}
return connect, nil, hasErr()
Expand Down Expand Up @@ -364,7 +364,7 @@ func testGetApplyConfig(t *testing.T) {
type checkFn func(*testing.T, string, error)

checkExpectedOutput := func(want string) func(*testing.T, string, error) {
return func(t *testing.T, got string, err error) {
return func(t *testing.T, got string, _ error) {
// remove spacing issues by removing white space and new line characters
// want := strings.ReplaceAll(strings.ReplaceAll(expected, "\n", ""), " ", "")
// got := strings.ReplaceAll(strings.ReplaceAll(result, "\n", ""), " ", "")
Expand Down Expand Up @@ -431,7 +431,7 @@ func testGetStorageSecret(t *testing.T) {
type checkFn func(*testing.T, []byte, error)

checkExpectedOutput := func(want []byte) func(*testing.T, []byte, error) {
return func(t *testing.T, got []byte, err error) {
return func(t *testing.T, got []byte, _ error) {
if !bytes.Equal(want, got) {
t.Errorf("want %s, got %s", string(want), string(got))
}
Expand Down
4 changes: 2 additions & 2 deletions internal/proxy/dispatch_handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ func testConfiguredDispatchHandler(t *testing.T) {
log := logrus.New().WithContext(ctx)
h := proxy.NewDispatchHandler(log,
map[string]http.Handler{
"powerflex": http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
"powerflex": http.HandlerFunc(func(_ http.ResponseWriter, _ *http.Request) {
}),
})

Expand All @@ -91,7 +91,7 @@ func testForwardedHeaders(t *testing.T) {
log := logrus.New().WithContext(ctx)
h := proxy.NewDispatchHandler(log,
map[string]http.Handler{
"powerflex": http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
"powerflex": http.HandlerFunc(func(_ http.ResponseWriter, _ *http.Request) {
}),
})

Expand Down
14 changes: 7 additions & 7 deletions internal/proxy/powerflex_handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,9 @@ func TestPowerFlex(t *testing.T) {
r := httptest.NewRequest(http.MethodGet, "/api/login", nil)
// Build a fake powerflex backend, since it will try to login for real.
// We'll use the URL of this test server as part of the systems config.
fakePowerFlex := buildTestTLSServer(t, http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
fakePowerFlex := buildTestTLSServer(t, http.HandlerFunc(func(_ http.ResponseWriter, _ *http.Request) {
}))
fakeOPA := buildTestServer(t, http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
fakeOPA := buildTestServer(t, http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
w.Write([]byte(`{"result": {"allow": true}}`))
}))
// Add headers that the sidecar-proxy would add, in order to identify
Expand Down Expand Up @@ -112,13 +112,13 @@ func TestPowerFlex(t *testing.T) {
// Build a fake powerflex backend, since it will try to login for real.
// We'll use the URL of this test server as part of the systems config.
done := make(chan struct{})
fakePowerFlex := buildTestTLSServer(t, http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
fakePowerFlex := buildTestTLSServer(t, http.HandlerFunc(func(_ http.ResponseWriter, _ *http.Request) {
t.Logf("Test request path is %q", r.URL.Path)
if r.URL.Path == "/api/version/" {
done <- struct{}{}
}
}))
fakeOPA := buildTestServer(t, http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
fakeOPA := buildTestServer(t, http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
w.Write([]byte(`{"result": {"allow": true}}`))
}))
// Add headers that the sidecar-proxy would add, in order to identify
Expand Down Expand Up @@ -1467,7 +1467,7 @@ func mocktenantKey(name string) string {
}

func newTestRouter() *web.Router {
noopHandler := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {})
noopHandler := http.HandlerFunc(func(_ http.ResponseWriter, _ *http.Request) {})
return &web.Router{
ProxyHandler: noopHandler,
RolesHandler: noopHandler,
Expand All @@ -1483,7 +1483,7 @@ func buildTestTLSServer(t *testing.T, h ...http.Handler) *httptest.Server {
var handler http.Handler
switch len(h) {
case 0:
handler = http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {})
handler = http.HandlerFunc(func(_ http.ResponseWriter, _ *http.Request) {})
case 1:
handler = h[0]
}
Expand All @@ -1498,7 +1498,7 @@ func buildTestServer(t *testing.T, h ...http.Handler) *httptest.Server {
var handler http.Handler
switch len(h) {
case 0:
handler = http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {})
handler = http.HandlerFunc(func(_ http.ResponseWriter, _ *http.Request) {})
case 1:
handler = h[0]
}
Expand Down
20 changes: 10 additions & 10 deletions internal/proxy/powermax_handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func testPowerMaxServeHTTP(t *testing.T) {
t.Run("it proxies requests", func(t *testing.T) {
done := make(chan struct{})
sut := buildPowerMaxHandler(t,
withUnisphereServer(func(w http.ResponseWriter, r *http.Request) {
withUnisphereServer(func(_ http.ResponseWriter, _ *http.Request) {
done <- struct{}{}
}),
)
Expand Down Expand Up @@ -80,11 +80,11 @@ func testPowerMaxServeHTTP(t *testing.T) {
// the difference is that it uses a GET method.
// This test will ensure that httprouter handles both GET and PUT methods.
var gotCalled bool
fakeUni := fakeServer(t, http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
fakeUni := fakeServer(t, http.HandlerFunc(func(_ http.ResponseWriter, r *http.Request) {
t.Logf("fake unisphere received: %s %s", r.Method, r.URL)
gotCalled = true
}))
sut := buildPowerMaxHandler(t, withOPAServer(func(w http.ResponseWriter, r *http.Request) {
sut := buildPowerMaxHandler(t, withOPAServer(func(w http.ResponseWriter, _ *http.Request) {
fmt.Fprintf(w, `{ "result": { "allow": true } }`)
}))

Expand Down Expand Up @@ -131,7 +131,7 @@ func testPowerMaxServeHTTP(t *testing.T) {
},
}))
sut := buildPowerMaxHandler(t,
withOPAServer(func(w http.ResponseWriter, r *http.Request) {
withOPAServer(func(w http.ResponseWriter, _ *http.Request) {
fmt.Fprintf(w, `{ "result": { "allow": true } }`)
}),
withEnforcer(enf),
Expand Down Expand Up @@ -196,7 +196,7 @@ func testPowerMaxServeHTTP(t *testing.T) {
},
}))
sut := buildPowerMaxHandler(t,
withOPAServer(func(w http.ResponseWriter, r *http.Request) {
withOPAServer(func(w http.ResponseWriter, _ *http.Request) {
fmt.Fprintf(w, `{ "result": { "allow": true } }`)
}),
withEnforcer(enf),
Expand Down Expand Up @@ -354,28 +354,28 @@ func withOPAServer(h http.HandlerFunc) powermaxHandlerOption {
}

func withEnforcer(v *quota.RedisEnforcement) powermaxHandlerOption {
return func(t *testing.T, pmh *PowerMaxHandler) {
return func(_ *testing.T, pmh *PowerMaxHandler) {
pmh.enforcer = v
}
}

func withLogger(logger *logrus.Entry) powermaxHandlerOption {
return func(t *testing.T, pmh *PowerMaxHandler) {
return func(_ *testing.T, pmh *PowerMaxHandler) {
pmh.log = logger
}
}

func withSystem(s *PowerMaxSystem) powermaxHandlerOption {
return func(t *testing.T, pmh *PowerMaxHandler) {
return func(_ *testing.T, pmh *PowerMaxHandler) {
pmh.systems["1234567890"] = s
}
}

func buildPowerMaxHandler(t *testing.T, opts ...powermaxHandlerOption) *PowerMaxHandler {
defaultOptions := []powermaxHandlerOption{
withLogger(testLogger()), // order matters for this one.
withUnisphereServer(func(w http.ResponseWriter, r *http.Request) {}),
withOPAServer(func(w http.ResponseWriter, r *http.Request) {}),
withUnisphereServer(func(_ http.ResponseWriter, _ *http.Request) {}),
withOPAServer(func(_ http.ResponseWriter, _ *http.Request) {}),
}

ret := PowerMaxHandler{}
Expand Down
Loading

0 comments on commit dd55a30

Please sign in to comment.