buildTestConfig creates a minimal cli.App with appFlags(), runs it with the given args, and returns the appConfig produced by buildConfig.
(args []string)
| 13 | // buildTestConfig creates a minimal cli.App with appFlags(), runs it with the |
| 14 | // given args, and returns the appConfig produced by buildConfig. |
| 15 | func buildTestConfig(args []string) (*appConfig, error) { |
| 16 | var result *appConfig |
| 17 | var buildErr error |
| 18 | |
| 19 | app := &cli.App{ |
| 20 | Name: "gitbackup", |
| 21 | Flags: appFlags(), |
| 22 | Action: func(cCtx *cli.Context) error { |
| 23 | result, buildErr = buildConfig(cCtx) |
| 24 | return buildErr |
| 25 | }, |
| 26 | } |
| 27 | |
| 28 | // urfave/cli expects the program name as args[0] |
| 29 | fullArgs := append([]string{"gitbackup"}, args...) |
| 30 | if err := app.Run(fullArgs); err != nil { |
| 31 | return nil, fmt.Errorf("app.Run: %w", err) |
| 32 | } |
| 33 | return result, buildErr |
| 34 | } |
| 35 | |
| 36 | func TestHandleInitConfig(t *testing.T) { |
| 37 | tmpDir := t.TempDir() |
no test coverage detected