Skip to content

How to write unit tests foe commands? #1157

Description

@AchalaSB

my question is how to write unit test script for this function?

I have developed a cli mycli create will create a new file.

func cmd() {
  app := &cli.App{
    Commands: []*cli.Command{
      {
        Name:    "create",
        Usage:   "create file",
	Flags: []cli.Flag{
		&cli.StringFlag{Name: "message, m"},
	},
        Action:  func(c *cli.Context) error {
	 sample.SRCfile("hello/src")  // function to create new file
          return nil
        },
      },
      },
      },
    },
  }

func main() {
	cmd()
	err := app.Run(os.Args)
	if err != nil {
		log.Fatal(err)
	}
}

Thanks

Metadata

Metadata

Assignees

No one assigned

    Labels

    area/v2relates to / is being considered for v2kind/questionsomeone asking a questionstatus/triagemaintainers still need to look into this

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions