(ctx context.Context, logger *zap.Logger, _ *config.Config, serviceFactory ServiceFactory, cmdConfigurator CmdConfigurator)
| 16 | } |
| 17 | |
| 18 | func Test(ctx context.Context, logger *zap.Logger, _ *config.Config, serviceFactory ServiceFactory, cmdConfigurator CmdConfigurator) *cobra.Command { |
| 19 | var testCmd = &cobra.Command{ |
| 20 | Use: "test", |
| 21 | Short: "run the recorded testcases and execute assertions", |
| 22 | Example: `keploy test -c "/path/to/user/app" --delay 6`, |
| 23 | PreRunE: func(cmd *cobra.Command, _ []string) error { |
| 24 | return cmdConfigurator.Validate(ctx, cmd) |
| 25 | }, |
| 26 | RunE: func(cmd *cobra.Command, _ []string) error { |
| 27 | svc, err := serviceFactory.GetService(ctx, cmd.Name()) |
| 28 | if err != nil { |
| 29 | utils.LogError(logger, err, "failed to get service", zap.String("command", cmd.Name())) |
| 30 | return nil |
| 31 | } |
| 32 | var replay replaySvc.Service |
| 33 | var ok bool |
| 34 | if replay, ok = svc.(replaySvc.Service); !ok { |
| 35 | utils.LogError(logger, nil, "service doesn't satisfy replay service interface") |
| 36 | return nil |
| 37 | } |
| 38 | // defering the stop function to stop keploy in case of any error in test or in case of context cancellation |
| 39 | defer func() { |
| 40 | select { |
| 41 | case <-ctx.Done(): |
| 42 | break |
| 43 | default: |
| 44 | utils.ExecCancel() |
| 45 | } |
| 46 | }() |
| 47 | err = replay.Start(ctx) |
| 48 | if err != nil { |
| 49 | if ctx.Err() != context.Canceled { |
| 50 | utils.LogError(logger, err, "failed to replay") |
| 51 | } |
| 52 | } |
| 53 | |
| 54 | return nil |
| 55 | }, |
| 56 | } |
| 57 | |
| 58 | err := cmdConfigurator.AddFlags(testCmd) |
| 59 | if err != nil { |
| 60 | utils.LogError(logger, err, "failed to add test flags") |
| 61 | return nil |
| 62 | } |
| 63 | |
| 64 | return testCmd |
| 65 | } |
nothing calls this directly
no test coverage detected