Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: option to name test cases #903

Merged
merged 4 commits into from
Oct 6, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion pkg/hooks/connection/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ func capture(db platform.TestCaseDB, req *http.Request, resp *http.Response, log
// err = db.Insert(httpMock, getDeps())
err = db.WriteTestcase(&models.TestCase{
Version: models.V1Beta2,
Name: "",
Name: pkg.ToYamlHttpHeader(req.Header)["Keploy_test_name"],
AkashKumar7902 marked this conversation as resolved.
Show resolved Hide resolved
Kind: models.HTTP,
Created: time.Now().Unix(),
HttpReq: models.HttpReq{
Expand Down
6 changes: 5 additions & 1 deletion pkg/platform/yaml/yaml.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,18 +42,18 @@
// createYamlFile is used to create the yaml file along with the path directory (if does not exists)
func createYamlFile(path string, fileName string, Logger *zap.Logger) (bool, error) {
// checks id the yaml exists
if _, err := os.Stat(filepath.Join(path, fileName+".yaml")); err != nil {

Check failure

Code scanning / CodeQL

Uncontrolled data used in path expression High

This path depends on a
user-provided value
.
// creates the path director if does not exists
err = os.MkdirAll(filepath.Join(path), fs.ModePerm)
if err != nil {
Logger.Error("failed to create a directory for the yaml file", zap.Error(err), zap.Any("path directory", path), zap.Any("yaml", fileName))
return false, err
}

// create the yaml file
_, err := os.Create(filepath.Join(path, fileName+".yaml"))

Check failure

Code scanning / CodeQL

Uncontrolled data used in path expression High

This path depends on a
user-provided value
.
if err != nil {
Logger.Error("failed to create a yaml file", zap.Error(err), zap.Any("path directory", path), zap.Any("yaml", fileName))
return false, err
}

Expand Down Expand Up @@ -122,9 +122,9 @@
if err != nil {
return err
}
file, err := os.OpenFile(filepath.Join(path, fileName+".yaml"), os.O_CREATE|os.O_WRONLY|os.O_APPEND, os.ModePerm)

Check failure

Code scanning / CodeQL

Uncontrolled data used in path expression High

This path depends on a
user-provided value
.
if err != nil {
ys.Logger.Error("failed to open the created yaml file", zap.Error(err), zap.Any("yaml file name", fileName))
return err
}

Expand All @@ -134,14 +134,14 @@
}
d, err := yamlLib.Marshal(&doc)
if err != nil {
ys.Logger.Error("failed to marshal the recorded calls into yaml", zap.Error(err), zap.Any("yaml file name", fileName))
return err
}
data = append(data, d...)

_, err = file.Write(data)
if err != nil {
ys.Logger.Error("failed to write the yaml document", zap.Error(err), zap.Any("yaml file name", fileName))
return err
}
defer file.Close()
Expand All @@ -159,7 +159,11 @@
if err != nil {
return err
}
tcsName = fmt.Sprintf("test-%v", lastIndx)
if tc.Name == "" {
tcsName = fmt.Sprintf("test-%v", lastIndx)
} else {
tcsName = tc.Name
}
} else {
tcsName = ys.TcsName
}
Expand All @@ -178,7 +182,7 @@
ys.Logger.Error("failed to write testcase yaml file", zap.Error(err))
return err
}
ys.Logger.Info("🟠 Keploy has captured test cases for the user's application.", zap.String("path", ys.TcsPath), zap.String("testcase name", tcsName))

// write the mock yamls
// mockName := fmt.Sprintf("mock-%v", lastIndx)
Expand Down