Skip to content

Commit

Permalink
Update UT coverage for main.go
Browse files Browse the repository at this point in the history
  • Loading branch information
WilsonRadadia20 committed Feb 7, 2025
1 parent 68b681e commit 7ca028b
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 27 deletions.
54 changes: 27 additions & 27 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,30 @@ func main() {

const netUnix = "unix"

var printUsage = func(appName, appDescription, appUsage, binPath string) {
// app is the information passed to the printUsage function
app := struct {
Name string
Description string
Usage string
BinPath string
}{
appName,
appDescription,
appUsage,
binPath,
}

t, err := template.New("t").Parse(usage)
if err != nil {
log.WithError(err).Fatalln("failed to parse usage template")
}
if err := t.Execute(os.Stderr, app); err != nil {
log.WithError(err).Fatalln("failed emitting usage")
}
return
}

// Run launches a CSI storage plug-in.
func Run(
ctx context.Context,
Expand Down Expand Up @@ -82,44 +106,20 @@ func Run(
}
log.SetLevel(lvl)

printUsage := func() {
// app is the information passed to the printUsage function
app := struct {
Name string
Description string
Usage string
BinPath string
}{
appName,
appDescription,
appUsage,
os.Args[0],
}

t, err := template.New("t").Parse(usage)
if err != nil {
log.WithError(err).Fatalln("failed to parse usage template")
}
if err := t.Execute(os.Stderr, app); err != nil {
log.WithError(err).Fatalln("failed emitting usage")
}
return
}

// Check for a help flag.
fs := flag.NewFlagSet("csp", flag.ExitOnError)
fs.Usage = printUsage
// fs.Usage = printUsage(appName, appDescription, appUsage, os.Args[0])
var help bool
fs.BoolVar(&help, "?", false, "")
err := fs.Parse(os.Args)
if err == flag.ErrHelp || help {
printUsage()
printUsage(appName, appDescription, appUsage, os.Args[0])
os.Exit(1)
}

// If no endpoint is set then print the usage.
if os.Getenv(utils.EnvVarEndpoint) == "" {
printUsage()
printUsage(appName, appDescription, appUsage, os.Args[0])
os.Exit(1)
}

Expand Down
4 changes: 4 additions & 0 deletions main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,5 +157,9 @@ func TestRun(t *testing.T) {
os.Setenv("X_CSI_SPEC_DISABLE_LEN_CHECK", "true")

Run(ctx, appName, appDescription, appUsage, &MockPluginProvider{})
}

func TestPrintUsaae(t *testing.T) {

Check failure on line 162 in main_test.go

View workflow job for this annotation

GitHub Actions / Golang Validation / Lint golang code

unused-parameter: parameter 't' seems to be unused, consider removing or renaming it as _ (revive)
var appName, appDescription, appUsage, binPath string
printUsage(appName, appDescription, appUsage, binPath)
}

0 comments on commit 7ca028b

Please sign in to comment.