Skip to content

Commit

Permalink
Adding PR template and workflow (#6)
Browse files Browse the repository at this point in the history
Added PR template and workflow
Fixed gosec, formatting, linting issues
  • Loading branch information
spriya-m authored Feb 8, 2022
1 parent 92d840e commit c5d4415
Show file tree
Hide file tree
Showing 21 changed files with 332 additions and 134 deletions.
26 changes: 26 additions & 0 deletions .github/pull_request_template.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Description
A few sentences describing the overall goals of the pull request's commits.

# GitHub Issues
List the GitHub issues impacted by this PR:

| GitHub Issue # |
| -------------- |
| |

# Checklist:

- [ ] I have performed a self-review of my own code to ensure there are no formatting, vetting, linting, or security issues
- [ ] I have verified that new and existing unit tests pass locally with my changes
- [ ] I have not allowed coverage numbers to degenerate
- [ ] I have maintained at least 90% code coverage
- [ ] I have commented on my code, particularly in hard-to-understand areas
- [ ] I have made corresponding changes to the documentation
- [ ] I have added tests that prove my fix is effective or that my feature works
- [ ] Backward compatibility is not broken

# How Has This Been Tested?
Please describe the tests that you ran to verify your changes. Please also list any relevant details for your test configuration

- [ ] Test A
- [ ] Test B
38 changes: 38 additions & 0 deletions .github/workflows/actions.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
name: Workflow
on:
push:
branches: [ main ]
pull_request:
branches: [ main ]
jobs:
code-check:
name: Check Go formatting, linting, vetting
runs-on: ubuntu-latest
steps:
- name: Checkout the code
uses: actions/checkout@v2
- name: Run the formatter, linter, and vetter
uses: dell/common-github-actions/go-code-formatter-linter-vetter@main
with:
directories: ./...
go_security_scan:
name: Go security
runs-on: ubuntu-latest
steps:
- name: Checkout the code
uses: actions/checkout@v2
- name: Run Go Security
uses: securego/gosec@master
with:
args: ./...
malware_security_scan:
name: Malware Scanner
runs-on: ubuntu-latest
steps:
- name: Checkout the code
uses: actions/checkout@v2
- name: Run malware scan
uses: dell/common-github-actions/malware-scanner@main
with:
directories: .
options: -ri
32 changes: 16 additions & 16 deletions base_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ func (bmh *baseMockHelper) MultipathAddWWIDOK(

func (bmh *baseMockHelper) MultipathAddWWIDErr(
m *intmultipath.MockMultipath) *gomock.Call {
return bmh.MultipathAddWWIDCall(m).Return(mh.TestErr)
return bmh.MultipathAddWWIDCall(m).Return(mh.ErrTest)
}

func (bmh *baseMockHelper) MultipathAddPathCall(
Expand All @@ -69,7 +69,7 @@ func (bmh *baseMockHelper) MultipathAddPathOK(

func (bmh *baseMockHelper) MultipathAddPathErr(
m *intmultipath.MockMultipath) *gomock.Call {
return bmh.MultipathAddPathCall(m).Return(mh.TestErr)
return bmh.MultipathAddPathCall(m).Return(mh.ErrTest)
}

func (bmh *baseMockHelper) MultipathDelPathCall(
Expand All @@ -84,7 +84,7 @@ func (bmh *baseMockHelper) MultipathDelPathOK(

func (bmh *baseMockHelper) MultipathDelPathErr(
m *intmultipath.MockMultipath) *gomock.Call {
return bmh.MultipathDelPathCall(m).Return(mh.TestErr)
return bmh.MultipathDelPathCall(m).Return(mh.ErrTest)
}

func (bmh *baseMockHelper) MultipathFlushDeviceCall(
Expand All @@ -99,7 +99,7 @@ func (bmh *baseMockHelper) MultipathFlushDeviceOK(

func (bmh *baseMockHelper) MultipathFlushDeviceErr(
m *intmultipath.MockMultipath) *gomock.Call {
return bmh.MultipathFlushDeviceCall(m).Return(mh.TestErr)
return bmh.MultipathFlushDeviceCall(m).Return(mh.ErrTest)
}

func (bmh *baseMockHelper) MultipathIsDaemonRunningCall(
Expand All @@ -124,7 +124,7 @@ func (bmh *baseMockHelper) MultipathGetDMWWIDOK(

func (bmh *baseMockHelper) MultipathGetDMWWIDErr(
m *intmultipath.MockMultipath) *gomock.Call {
return bmh.MultipathGetDMWWIDCall(m).Return("", mh.TestErr)
return bmh.MultipathGetDMWWIDCall(m).Return("", mh.ErrTest)
}

func (bmh *baseMockHelper) SCSIIsDeviceExistCall(
Expand All @@ -149,7 +149,7 @@ func (bmh *baseMockHelper) SCSIRescanSCSIHostByHCTLOK(

func (bmh *baseMockHelper) SCSIRescanSCSIHostByHCTLErr(
m *intscsi.MockSCSI) *gomock.Call {
return bmh.SCSIRescanSCSIHostByHCTLCall(m).Return(mh.TestErr)
return bmh.SCSIRescanSCSIHostByHCTLCall(m).Return(mh.ErrTest)
}

func (bmh *baseMockHelper) SCSIRescanSCSIDeviceByHCTLCall(
Expand All @@ -164,7 +164,7 @@ func (bmh *baseMockHelper) SCSIRescanSCSIDeviceByHCTLOK(

func (bmh *baseMockHelper) SCSIRescanSCSIDeviceByHCTLErr(
m *intscsi.MockSCSI) *gomock.Call {
return bmh.SCSIRescanSCSIDeviceByHCTLCall(m).Return(mh.TestErr)
return bmh.SCSIRescanSCSIDeviceByHCTLCall(m).Return(mh.ErrTest)
}

func (bmh *baseMockHelper) SCSIDeleteSCSIDeviceByHCTLCall(
Expand All @@ -179,7 +179,7 @@ func (bmh *baseMockHelper) SCSIDeleteSCSIDeviceByHCTLOK(

func (bmh *baseMockHelper) SCSIDeleteSCSIDeviceByHCTLErr(
m *intscsi.MockSCSI) *gomock.Call {
return bmh.SCSIDeleteSCSIDeviceByHCTLCall(m).Return(mh.TestErr)
return bmh.SCSIDeleteSCSIDeviceByHCTLCall(m).Return(mh.ErrTest)
}

func (bmh *baseMockHelper) SCSIDeleteSCSIDeviceByNameCall(
Expand All @@ -194,7 +194,7 @@ func (bmh *baseMockHelper) SCSIDeleteSCSIDeviceByNameOK(

func (bmh *baseMockHelper) SCSIDeleteSCSIDeviceByNameErr(
m *intscsi.MockSCSI) *gomock.Call {
return bmh.SCSIDeleteSCSIDeviceByNameCall(m).Return(mh.TestErr)
return bmh.SCSIDeleteSCSIDeviceByNameCall(m).Return(mh.ErrTest)
}

func (bmh *baseMockHelper) SCSIDeleteSCSIDeviceByPathCall(
Expand All @@ -209,7 +209,7 @@ func (bmh *baseMockHelper) SCSIDeleteSCSIDeviceByPathOK(

func (bmh *baseMockHelper) SCSIDeleteSCSIDeviceByPathErr(
m *intscsi.MockSCSI) *gomock.Call {
return bmh.SCSIDeleteSCSIDeviceByPathCall(m).Return(mh.TestErr)
return bmh.SCSIDeleteSCSIDeviceByPathCall(m).Return(mh.ErrTest)
}

func (bmh *baseMockHelper) SCSIGetDeviceWWNCall(
Expand All @@ -224,7 +224,7 @@ func (bmh *baseMockHelper) SCSIGetDeviceWWNOK(

func (bmh *baseMockHelper) SCSIGetDeviceWWNErr(
m *intscsi.MockSCSI) *gomock.Call {
return bmh.SCSIGetDeviceWWNCall(m).Return("", mh.TestErr)
return bmh.SCSIGetDeviceWWNCall(m).Return("", mh.ErrTest)
}

func (bmh *baseMockHelper) SCSIGetDevicesByWWNCall(
Expand All @@ -239,7 +239,7 @@ func (bmh *baseMockHelper) SCSIGetDevicesByWWNOK(

func (bmh *baseMockHelper) SCSIGetDevicesByWWNErr(
m *intscsi.MockSCSI) *gomock.Call {
return bmh.SCSIGetDevicesByWWNCall(m).Return(nil, mh.TestErr)
return bmh.SCSIGetDevicesByWWNCall(m).Return(nil, mh.ErrTest)
}

func (bmh *baseMockHelper) SCSIGetDMDeviceByChildrenCall(
Expand All @@ -254,7 +254,7 @@ func (bmh *baseMockHelper) SCSIGetDMDeviceByChildrenOK(

func (bmh *baseMockHelper) SCSIGetDMDeviceByChildrenErr(
m *intscsi.MockSCSI) *gomock.Call {
return bmh.SCSIGetDMDeviceByChildrenCall(m).Return("", mh.TestErr)
return bmh.SCSIGetDMDeviceByChildrenCall(m).Return("", mh.ErrTest)
}

func (bmh *baseMockHelper) SCSIGetDMChildrenCall(
Expand All @@ -267,7 +267,7 @@ func (bmh *baseMockHelper) SCSIGetDMChildrenOK(
}
func (bmh *baseMockHelper) SCSIGetDMChildrenErr(
m *intscsi.MockSCSI) *gomock.Call {
return bmh.SCSIGetDMChildrenCall(m).Return(nil, mh.TestErr)
return bmh.SCSIGetDMChildrenCall(m).Return(nil, mh.ErrTest)
}

func (bmh *baseMockHelper) SCSICheckDeviceIsValidCall(
Expand All @@ -292,7 +292,7 @@ func (bmh *baseMockHelper) SCSIGetDeviceNameByHCTLOK(

func (bmh *baseMockHelper) SCSIGetDeviceNameByHCTLErr(
m *intscsi.MockSCSI) *gomock.Call {
return bmh.SCSIGetDeviceNameByHCTLCall(m).Return("", mh.TestErr)
return bmh.SCSIGetDeviceNameByHCTLCall(m).Return("", mh.ErrTest)
}

func (bmh *baseMockHelper) SCSIWaitUdevSymlinkCall(
Expand All @@ -308,7 +308,7 @@ func (bmh *baseMockHelper) SCSIWaitUdevSymlinkOK(

func (bmh *baseMockHelper) SCSIWaitUdevSymlinkErr(
m *intscsi.MockSCSI) *gomock.Call {
return bmh.SCSIWaitUdevSymlinkCall(m).Return(mh.TestErr)
return bmh.SCSIWaitUdevSymlinkCall(m).Return(mh.ErrTest)
}

func BaseConnectorCleanDeviceMock(mock *baseMockHelper,
Expand Down
2 changes: 1 addition & 1 deletion fc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ package gobrick

import (
"context"
"fmt"
"github.com/dell/gobrick/internal/mockhelper"
intmultipath "github.com/dell/gobrick/internal/multipath"
intscsi "github.com/dell/gobrick/internal/scsi"
wrp "github.com/dell/gobrick/internal/wrappers"
"fmt"
"github.com/golang/mock/gomock"
"golang.org/x/sync/semaphore"
"reflect"
Expand Down
7 changes: 6 additions & 1 deletion gobrick.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,23 @@
package gobrick

import (
"time"

"github.com/dell/gobrick/internal/logger"
"github.com/dell/gobrick/internal/tracer"
"time"
)

// Device defines device info
type Device struct {
WWN string
Name string
MultipathID string
}

// Logger defines logger interface used
type Logger = logger.Logger

// Tracer defines tracing interface used
type Tracer = tracer.Tracer

// SetLogger set custom logger for gobrick
Expand Down
2 changes: 1 addition & 1 deletion gobrick_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ package gobrick

import (
"context"
"fmt"
"github.com/dell/gobrick/internal/logger"
"github.com/dell/gobrick/internal/mockhelper"
"github.com/dell/gobrick/internal/tracer"
"github.com/dell/gobrick/pkg/scsi"
"fmt"
"github.com/stretchr/testify/assert"
"strconv"
"testing"
Expand Down
10 changes: 10 additions & 0 deletions internal/logger/logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ func init() {
logger = &DummyLogger{}
}

// SetLogger initializes custom logger for gobrick
func SetLogger(customLogger Logger) {
logger = customLogger
}
Expand All @@ -23,26 +24,35 @@ type Logger interface {
Error(ctx context.Context, format string, args ...interface{})
}

// DummyLogger for testing purposes
type DummyLogger struct{}

// Info is a dummy implementation of logger Info method
func (dl *DummyLogger) Info(ctx context.Context, format string, args ...interface{}) {
log.Print("INFO: " + fmt.Sprintf(format, args...))
}

// Debug is a dummy implementation of logger Debug method
func (dl *DummyLogger) Debug(ctx context.Context, format string, args ...interface{}) {
log.Print("DEBUG: " + fmt.Sprintf(format, args...))
}

// Error is a dummy implementation of logger Error method
func (dl *DummyLogger) Error(ctx context.Context, format string, args ...interface{}) {
log.Print("ERROR: " + fmt.Sprintf(format, args...))
}

// Info is a wrapper of logger Info method
func Info(ctx context.Context, format string, args ...interface{}) {
logger.Info(ctx, format, args...)
}

// Debug is a wrapper of logger Debug method
func Debug(ctx context.Context, format string, args ...interface{}) {
logger.Debug(ctx, format, args...)
}

// Error is a wrapper of logger Error method
func Error(ctx context.Context, format string, args ...interface{}) {
logger.Error(ctx, format, args...)
}
Loading

0 comments on commit c5d4415

Please sign in to comment.