Skip to content

Commit

Permalink
Bug Fix: Keploy test runs succesfully with no test cases (keploy#1597)
Browse files Browse the repository at this point in the history
* Bug Fix: Keply test runs succcesfully with no test cases

Signed-off-by: Akash <akashsingh2210670@gmail.com>

* Added warnings for Missing Keploy Folder, Missing test sets

Signed-off-by: Akash Singh <akashsingh2210670@gmail.com>

* Fixed Liny

Signed-off-by: Akash Singh <akashsingh2210670@gmail.com>

* Refactored requested changes

Signed-off-by: Akash Singh <akashsingh2210670@gmail.com>

* Changed log statement

Signed-off-by: Akash Singh <akashsingh2210670@gmail.com>

---------

Signed-off-by: Akash <akashsingh2210670@gmail.com>
Signed-off-by: Akash Singh <akashsingh2210670@gmail.com>
Co-authored-by: Animesh Pathak <53110238+Sonichigo@users.noreply.github.com>
Co-authored-by: Neha Gupta <gneha21@yahoo.in>
  • Loading branch information
3 people authored Apr 15, 2024
1 parent cca2d42 commit 714ad96
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 5 deletions.
9 changes: 9 additions & 0 deletions cli/provider/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"github.com/spf13/cobra"
"github.com/spf13/viper"
"go.keploy.io/server/v2/config"
"go.keploy.io/server/v2/pkg/models"
"go.keploy.io/server/v2/utils"
"go.keploy.io/server/v2/utils/log"
"go.uber.org/zap"
Expand Down Expand Up @@ -387,6 +388,14 @@ func (c *CmdConfigurator) ValidateFlags(ctx context.Context, cmd *cobra.Command)

c.cfg.Path = absPath + "/keploy"
if cmd.Name() == "test" {
//check if the keploy folder exists
if _, err := os.Stat(c.cfg.Path); os.IsNotExist(err) {
recordCmd := models.HighlightGrayString("keploy record")
errMsg := fmt.Sprintf("No test-sets found. Please record testcases using %s command", recordCmd)
utils.LogError(c.logger, nil, errMsg)
return errors.New(errMsg)
}

testSets, err := cmd.Flags().GetStringSlice("testsets")
if err != nil {
errMsg := "failed to get the testsets"
Expand Down
17 changes: 12 additions & 5 deletions pkg/service/replay/replay.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,20 +90,27 @@ func (r *Replayer) Start(ctx context.Context) error {
}
}()

// BootReplay will start the hooks and proxy and return the testRunID and appID
testRunID, appID, hookCancel, err := r.BootReplay(ctx)
testSetIDs, err := r.testDB.GetAllTestSetIDs(ctx)
if err != nil {
stopReason = fmt.Sprintf("failed to boot replay: %v", err)
stopReason = fmt.Sprintf("failed to get all test set ids: %v", err)
utils.LogError(r.logger, err, stopReason)
if err == context.Canceled {
return err
}
return fmt.Errorf(stopReason)
}

testSetIDs, err := r.testDB.GetAllTestSetIDs(ctx)
if len(testSetIDs) == 0 {
recordCmd := models.HighlightGrayString("keploy record")
errMsg := fmt.Sprintf("No test sets found in the keploy folder. Please record testcases using %s command", recordCmd)
utils.LogError(r.logger, err, errMsg)
return fmt.Errorf(errMsg)
}

// BootReplay will start the hooks and proxy and return the testRunID and appID
testRunID, appID, hookCancel, err := r.BootReplay(ctx)
if err != nil {
stopReason = fmt.Sprintf("failed to get all test set ids: %v", err)
stopReason = fmt.Sprintf("failed to boot replay: %v", err)
utils.LogError(r.logger, err, stopReason)
if err == context.Canceled {
return err
Expand Down

0 comments on commit 714ad96

Please sign in to comment.