Skip to content

Commit

Permalink
feat: handled review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
Hardikl committed Jul 9, 2024
1 parent 596cb0c commit f73eb19
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 0 deletions.
7 changes: 7 additions & 0 deletions cmd/collectors/commonutils.go
Original file line number Diff line number Diff line change
Expand Up @@ -265,3 +265,10 @@ func SplitVscanName(ontapName string) (string, string, string, bool) {
}
return ontapName[:firstColon], ontapName[firstColon+1 : lastColon], ontapName[lastColon+1:], true
}

func RunPlugin(runPluginIfNoData bool, mat map[string]*matrix.Matrix, err error) (map[string]*matrix.Matrix, error) {
if runPluginIfNoData {
return mat, nil
}
return nil, err
}
34 changes: 34 additions & 0 deletions cmd/collectors/commonutils_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package collectors

import (
"errors"
"github.com/netapp/harvest/v2/pkg/errs"
"github.com/netapp/harvest/v2/pkg/logging"
"github.com/netapp/harvest/v2/pkg/matrix"
"github.com/netapp/harvest/v2/pkg/tree/node"
Expand Down Expand Up @@ -396,3 +398,35 @@ func Test_SplitVscanName(t *testing.T) {
})
}
}

func TestRunPlugin(t *testing.T) {
type test struct {
name string
runPluginIfNoData bool
mat map[string]*matrix.Matrix
err error
wantMatrix bool
wantErr error
}

testMat := make(map[string]*matrix.Matrix)
err := errs.New(errs.ErrConfig, "test Error")

tests := []test{
{"runPluginIfNoData_false", false, testMat, err, false, err},
{"runPluginIfNoData_true", true, testMat, err, true, nil},
}

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got, err := RunPlugin(tt.runPluginIfNoData, tt.mat, tt.err)
if !errors.Is(err, tt.wantErr) {
t.Errorf("RunPlugin() error = %v, wantErr %v", err, tt.wantErr)
return
}
if (got != nil) != tt.wantMatrix {
t.Errorf("RunPlugin() got = %v, wantMatrix %v", got, tt.wantMatrix)
}
})
}
}

0 comments on commit f73eb19

Please sign in to comment.