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: autogenerate config if it doesn't already exist at the path #1773

Open
wants to merge 21 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
b33abac
fix: work in progress
PranshuSrivastava Mar 31, 2024
eb5d035
feat: auto gen config file if it does not exist
PranshuSrivastava Apr 2, 2024
ee03efc
fix: fix ci errors
PranshuSrivastava Apr 4, 2024
bbc901e
Merge branch 'main' into autogen-config
PranshuSrivastava Apr 4, 2024
941c9c6
Merge branch 'main' into autogen-config
PranshuSrivastava Apr 29, 2024
2787589
Merge branch 'main' into autogen-config
PranshuSrivastava May 7, 2024
83a4595
chore: checking the pipeline
PranshuSrivastava May 7, 2024
dde140f
chore: fix merge conflicts and checking failing test
PranshuSrivastava May 9, 2024
22dab02
Merge branch 'autogen-config' of https://github.com/keploy/keploy int…
PranshuSrivastava May 9, 2024
feb811d
chore: fix merge conflicts and checking failing test
PranshuSrivastava May 9, 2024
cc1829e
Merge branch 'main' into autogen-config
PranshuSrivastava May 13, 2024
45a86af
fix: trimming /keploy from the path
PranshuSrivastava May 13, 2024
b9f5816
fix: updated checking location
PranshuSrivastava May 14, 2024
9b79de1
fix: removed unnecessary changes
PranshuSrivastava May 14, 2024
e844206
Merge branch 'main' into autogen-config
PranshuSrivastava May 20, 2024
877a158
fix: made changes according to the comments
PranshuSrivastava May 20, 2024
cec6389
fix: changing local variables instead of the actual config
PranshuSrivastava May 21, 2024
1b2684e
Merge branch 'main' into autogen-config
Sarthak160 May 23, 2024
7107851
Merge branch 'main' into autogen-config
PranshuSrivastava May 27, 2024
3f6ce5e
fix: making deep copy of the config variable
PranshuSrivastava May 27, 2024
980b739
fix: linting issues and node on docker failing
PranshuSrivastava May 27, 2024
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 .github/workflows/test_workflow_scripts/java-linux.sh
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ sleep 5
done

# Start keploy in test mode.
sudo -E env PATH=$PATH ./../../../keployv2 test -c 'java -jar target/spring-petclinic-rest-3.0.2.jar' --delay 20 --generateGithubActions=false
sudo -E env PATH=$PATH ./../../../keployv2 test -c 'java -jar target/spring-petclinic-rest-3.0.2.jar' --delay 20 --generateGithubActions=false

# Get the test results from the testReport file.
report_file="./keploy/reports/test-run-0/test-set-0-report.yaml"
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/test_workflow_scripts/node-docker.sh
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,12 @@ curl -X GET http://localhost:8000/students
sleep 5

# Stop keploy.
docker rm -f keploy-v2
docker rm -f nodeMongoApp
docker stop keploy-v2
docker stop nodeMongoApp
done

# Start keploy in test mode.
sudo -E env PATH=$PATH ./../../keployv2 test -c "docker run -p 8000:8000 --name nodeMongoApp --network keploy-network node-app:1.0" --containerName nodeMongoApp --apiTimeout 30 --delay 30 --generateGithubActions=false
sudo -E env PATH=$PATH ./../../keployv2 test -c "docker run -p 8000:8000 --name nodeMongoApp --network keploy-network node-app:1.0" --containerName nodeMongoApp --apiTimeout 30 --delay 30 --generateGithubActions=false

# Get the test results from the testReport file.
report_file="./keploy/reports/test-run-0/test-set-0-report.yaml"
Expand Down
3 changes: 0 additions & 3 deletions .github/workflows/test_workflow_scripts/node-linux.sh
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,6 @@ sudo -E env PATH=$PATH ./../../keployv2 test -c 'npm start' --delay 10 --generat

sudo -E env PATH=$PATH ./../../keployv2 test -c 'npm start' --delay 10 --testsets test-set-0 --generateGithubActions=false

# Generate the keploy-config file.
sudo ./../../keployv2 config --generate

# Update the global noise to ts.
config_file="./keploy.yml"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how will these filters appended to the config if you are not generating them ahead..?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in our case the config file would have already been generated when we are running keploy in the record and the test mode. So this command is not needed now, we can just edit the same keploy config file.

sed -i 's/selectedTests: {}/selectedTests: {"test-set-0": ["test-1", "test-2"]}/' "$config_file"
Expand Down
14 changes: 7 additions & 7 deletions cli/provider/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,18 +45,18 @@ var Examples = `
Golang Application
Record:
sudo -E env PATH=$PATH keploy record -c "/path/to/user/app/binary"

Test:
sudo -E env PATH=$PATH keploy test -c "/path/to/user/app/binary" --delay 10

Node Application
Record:
sudo -E env PATH=$PATH keploy record -c “npm start --prefix /path/to/node/app"

Test:
sudo -E env PATH=$PATH keploy test -c “npm start --prefix /path/to/node/app" --delay 10

Java
Java
Record:
sudo -E env PATH=$PATH keploy record -c "java -jar /path/to/java-project/target/jar"

Expand All @@ -80,18 +80,18 @@ var ExampleOneClickInstall = `
Golang Application
Record:
keploy record -c "/path/to/user/app/binary"

Test:
keploy test -c "/path/to/user/app/binary" --delay 10

Node Application
Record:
keploy record -c “npm start --prefix /path/to/node/app"

Test:
keploy test -c “npm start --prefix /path/to/node/app" --delay 10

Java
Java
Record:
keploy record -c "java -jar /path/to/java-project/target/jar"

Expand Down Expand Up @@ -295,7 +295,7 @@ func (c *CmdConfigurator) ValidateFlags(ctx context.Context, cmd *cobra.Command)
utils.LogError(c.logger, err, errMsg)
return errors.New(errMsg)
}
c.logger.Info("config file not found; proceeding with flags only")
c.logger.Info("config file not found; creating one and proceeding with flags.")
}
}
if err := viper.Unmarshal(c.cfg); err != nil {
Expand Down
41 changes: 41 additions & 0 deletions cli/provider/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package provider
import (
"context"
"errors"
"strings"

"go.keploy.io/server/v2/config"
"go.keploy.io/server/v2/pkg/core"
Expand All @@ -20,6 +21,7 @@ import (
"go.keploy.io/server/v2/pkg/service/tools"
"go.keploy.io/server/v2/utils"
"go.uber.org/zap"
"gopkg.in/yaml.v3"
)

type ServiceProvider struct {
Expand Down Expand Up @@ -84,6 +86,45 @@ func (n *ServiceProvider) GetService(ctx context.Context, cmd string) (interface
return tools.NewTools(n.logger, tel), nil
// TODO: add case for mock
case "record", "test", "mock", "normalize":
// Check if the config file exists on the path or not and if it does not, we create it.
if !utils.CheckFileExists("keploy.yml") {
toolsService := tools.NewTools(n.logger, tel)
config := &config.Config{
Path: n.cfg.Path,
AppID: n.cfg.AppID,
ReRecord: n.cfg.ReRecord,
Command: n.cfg.Command,
Port: n.cfg.Port,
DNSPort: n.cfg.DNSPort,
ProxyPort: n.cfg.ProxyPort,
Debug: n.cfg.Debug,
DisableTele: n.cfg.DisableTele,
DisableANSI: n.cfg.DisableANSI,
InDocker: n.cfg.InDocker,
ContainerName: n.cfg.ContainerName,
NetworkName: n.cfg.NetworkName,
BuildDelay: n.cfg.BuildDelay,
Test: n.cfg.Test,
Record: n.cfg.Record,
Normalize: n.cfg.Normalize,
ConfigPath: n.cfg.ConfigPath,
BypassRules: n.cfg.BypassRules,
EnableTesting: n.cfg.EnableTesting,
GenerateGithubActions: n.cfg.GenerateGithubActions,
KeployContainer: n.cfg.KeployContainer,
KeployNetwork: n.cfg.KeployNetwork,
CommandType: n.cfg.CommandType,
}
config.Path = strings.TrimSuffix(config.Path, "/keploy")
yamlData, err := yaml.Marshal(config)
if err != nil {
n.logger.Debug("failed to marshal the config")
}
err = toolsService.CreateConfig(ctx, "keploy.yml", string(yamlData))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you provide a screenshot by using 3 flags like selected test-sets etc and generate the config file..?

if err != nil {
n.logger.Debug("failed to create the config file", zap.Error(err))
}
}
commonServices := n.GetCommonServices(*n.cfg)
if cmd == "record" {
return record.New(n.logger, commonServices.YamlTestDB, commonServices.YamlMockDb, tel, commonServices.Instrumentation, *n.cfg), nil
Expand Down