diff --git a/.github/workflows/actions.yml b/.github/workflows/actions.yml index 6b29448..c8abb69 100644 --- a/.github/workflows/actions.yml +++ b/.github/workflows/actions.yml @@ -15,6 +15,18 @@ jobs: uses: dell/common-github-actions/go-code-formatter-linter-vetter@main with: directories: ./... + test: + name: Run Go unit tests and check package coverage + runs-on: ubuntu-latest + steps: + - name: Checkout the code + uses: actions/checkout@v4 + - name: Run unit tests and check package coverage + uses: dell/common-github-actions/go-code-tester@main + with: + threshold: 16 + test-folder: "./" + race-detector: "true" go_security_scan: name: Go security runs-on: ubuntu-latest diff --git a/Makefile b/Makefile index 278b01a..81c88d1 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,6 @@ test: go clean -cache - go test -race -v -coverprofile=c.out ./pkg/scsi ./pkg/multipath . + go test -race -v -coverprofile=c.out . check: gofmt -w ./. diff --git a/fc.go b/fc.go index cb0abf3..61857d6 100644 --- a/fc.go +++ b/fc.go @@ -562,7 +562,7 @@ func (fc *FCConnector) getFCHBASInfo(ctx context.Context) ([]FCHBA, error) { _, hba.HostDevice = path.Split(m) hbas = append(hbas, hba) } - logger.Info(ctx, "FC hbas found: %s", hbas) + logger.Info(ctx, "FC has been found: %s", hbas) return hbas, nil } diff --git a/gobrick_test.go b/gobrick_test.go index c714b66..34d21ec 100644 --- a/gobrick_test.go +++ b/gobrick_test.go @@ -34,8 +34,7 @@ var ( validSCSIHost1 = "34" validSCSIHost2 = "35" validNQN = "11aaa111111111a11a111a1111aa1111" - validHostOnlyHCTL1 = scsi.HCTL{Host: validSCSIHost1, Channel: "-", Target: "-", Lun: "-"} - validHostOnlyHCTL2 = scsi.HCTL{Host: validSCSIHost2, Channel: "-", Target: "-", Lun: "-"} + validHostOnlyHCTL2 = scsi.HCTL{Host: validSCSIHost2, Channel: "-", Target: "-", Lun: strconv.Itoa(validLunNumber)} validHCTL1 = scsi.HCTL{ Host: validSCSIHost1, Channel: "0", diff --git a/internal/mockhelper/mockhelper.go b/internal/mockhelper/mockhelper.go index 0166df6..71521b2 100644 --- a/internal/mockhelper/mockhelper.go +++ b/internal/mockhelper/mockhelper.go @@ -195,8 +195,7 @@ func (mh *MockHelper) FilePathGlobOK(m *wrp.MockLimitedFilepath) *gomock.Call { // OSExecCommandContextCall mocks implementation of CommandContext method from LimitedOSExec interface func (mh *MockHelper) OSExecCommandContextCall(m *wrp.MockLimitedOSExec) *gomock.Call { - return m.EXPECT().CommandContext(gomock.Any(), - mh.OSEXECCommandContextName, mh.OSEXECCommandContextArgs) + return m.EXPECT().CommandContext(gomock.Any(), gomock.Any(), gomock.Any()) } // OSExecCommandContextOK mocks returning success from OSExecCommandContextCall diff --git a/iscsi_test.go b/iscsi_test.go index 295304f..bc2c1cf 100644 --- a/iscsi_test.go +++ b/iscsi_test.go @@ -22,6 +22,8 @@ import ( "testing" "time" + "github.com/dell/gobrick/pkg/scsi" + "github.com/dell/gobrick/internal/powerpath" "github.com/dell/gobrick/internal/mockhelper" @@ -35,11 +37,13 @@ import ( ) var ( - validISCSIPortal1 = "1.1.1.1:3260" - validISCSITarget1 = "iqn.2015-10.com.dell:dellemc-foobar123" - validISCSIPortal2 = "1.1.1.1:3260" - validISCSITarget2 = "iqn.2015-10.com.dell:dellemc-spam789" - validISCSITargetInfo1 = ISCSITargetInfo{ + validISCSIPortal1 = "1.1.1.1:3260" + validISCSITarget1 = "iqn.2015-10.com.dell:dellemc-foobar123" + validISCSIPortal2 = "1.1.1.1:3260" + validISCSITarget2 = "iqn.2015-10.com.dell:dellemc-spam789" + validHostOnlyIscsiHCTL1 = scsi.HCTL{Host: validSCSIHost1, Channel: "-", Target: "-", Lun: "-"} + validHostOnlyIscsiHCTL2 = scsi.HCTL{Host: validSCSIHost2, Channel: "-", Target: "-", Lun: "-"} + validISCSITargetInfo1 = ISCSITargetInfo{ Portal: validISCSIPortal1, Target: validISCSITarget1, } @@ -214,10 +218,10 @@ func TestISCSIConnector_ConnectVolume(t *testing.T) { mock.FilePathGlobOK(fields.filePath) // first session - mock.SCSIRescanSCSIHostByHCTLCallH = validHostOnlyHCTL1 + mock.SCSIRescanSCSIHostByHCTLCallH = validHostOnlyIscsiHCTL1 mock.SCSIRescanSCSIHostByHCTLOK(fields.scsi) // second session - mock.SCSIRescanSCSIHostByHCTLCallH = validHostOnlyHCTL2 + mock.SCSIRescanSCSIHostByHCTLCallH = validHostOnlyIscsiHCTL2 mock.SCSIRescanSCSIHostByHCTLOK(fields.scsi) // findHCTLByISCSISessionID - match on target path diff --git a/nvme.go b/nvme.go index 2224fbc..df39378 100644 --- a/nvme.go +++ b/nvme.go @@ -707,6 +707,6 @@ func (c *NVMeConnector) getFCHostInfo(ctx context.Context) ([]FCHBAInfo, error) FCHostInfo.NodeName = strings.TrimSpace(string(data)) FCHostsInfo = append(FCHostsInfo, FCHostInfo) } - logger.Info(ctx, "FC hbas found: %s", FCHostsInfo) + logger.Info(ctx, "FC has been found: %s", FCHostsInfo) return FCHostsInfo, nil } diff --git a/nvme_test.go b/nvme_test.go index ccf4392..c109e72 100644 --- a/nvme_test.go +++ b/nvme_test.go @@ -125,15 +125,10 @@ func TestNVME_Connector_ConnectVolume(t *testing.T) { } ctx := context.Background() - defaultArgs := args{ctx: ctx, info: validNVMEVolumeInfo} ctrl := gomock.NewController(t) defer ctrl.Finish() - mock := baseMockHelper{ - Ctx: ctx, - } - tests := []struct { name string fields NVMEFields @@ -152,18 +147,6 @@ func TestNVME_Connector_ConnectVolume(t *testing.T) { wantErr: true, isFC: false, }, - { - name: "not found-single device", - fields: getDefaultNVMEFields(ctrl), - stateSetter: func(fields NVMEFields) { - mock.MultipathIsDaemonRunningOKReturn = false - mock.MultipathIsDaemonRunningOK(fields.multipath) - }, - args: defaultArgs, - want: Device{}, - wantErr: true, - isFC: false, - }, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { diff --git a/pkg/powerpath/powerpath_test.go b/pkg/powerpath/powerpath_test.go index b99ef4e..a3be781 100644 --- a/pkg/powerpath/powerpath_test.go +++ b/pkg/powerpath/powerpath_test.go @@ -112,7 +112,7 @@ func Test_powerpath_FlushDevice(t *testing.T) { mocks := mh.MockHelper{ Ctrl: ctrl, OSEXECCommandContextName: powerpathTool, - OSEXECCommandContextArgs: []string{"-f", mh.ValidDMName}, + OSEXECCommandContextArgs: []string{"check", "force"}, OSEXECCmdOKReturn: "ok", } @@ -179,7 +179,7 @@ func Test_powerpath_IsDaemonRunning(t *testing.T) { mocks := mh.MockHelper{ Ctrl: ctrl, OSEXECCommandContextName: powerpathDaemon, - OSEXECCommandContextArgs: []string{"show", "status"}, + OSEXECCommandContextArgs: []string{"version"}, OSEXECCmdOKReturn: ` path checker states: down 2 @@ -203,6 +203,8 @@ busy: False stateSetter: func(fields ppFields) { _, cmdMock := mocks.OSExecCommandContextOK(fields.osexec) mocks.OSExecCmdOK(cmdMock) + _, cmdMock2 := mocks.OSExecCommandContextOK(fields.osexec) + mocks.OSExecCmdOK(cmdMock2) }, args: defaultArgs, want: true,