-
-
Notifications
You must be signed in to change notification settings - Fork 380
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: make docker compose startup time configurable #1166
Changes from 12 commits
37a7fbd
51d4a21
85f5784
c053020
ac14827
b456e50
547292a
0e64d84
af6f371
28326aa
08278ba
1c5db17
01e89cc
514a195
661ed98
feece2c
8cf7e98
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,6 +6,7 @@ import ( | |
"os" | ||
"path/filepath" | ||
"strings" | ||
"time" | ||
|
||
"github.com/spf13/cobra" | ||
"go.keploy.io/server/pkg/models" | ||
|
@@ -38,7 +39,7 @@ func readTestConfig(configPath string) (*models.Test, error) { | |
return &doc.Test, nil | ||
} | ||
|
||
func (t *Test) getTestConfig(path *string, proxyPort *uint32, appCmd *string, testsets *[]string, appContainer, networkName *string, Delay *uint64, passThorughPorts *[]uint, apiTimeout *uint64, globalNoise *models.GlobalNoise, testSetNoise *models.TestsetNoise, coverageReportPath *string, withCoverage *bool, configPath string) error { | ||
func (t *Test) getTestConfig(path *string, proxyPort *uint32, appCmd *string, testsets *[]string, appContainer, networkName *string, Delay *uint64, buildDelay *time.Duration, passThorughPorts *[]uint, apiTimeout *uint64, globalNoise *models.GlobalNoise, testSetNoise *models.TestsetNoise, coverageReportPath *string, withCoverage *bool, configPath string) error { | ||
configFilePath := filepath.Join(configPath, "keploy-config.yaml") | ||
if isExist := utils.CheckFileExists(configFilePath); !isExist { | ||
return errFileNotFound | ||
|
@@ -68,6 +69,9 @@ func (t *Test) getTestConfig(path *string, proxyPort *uint32, appCmd *string, te | |
if *Delay == 5 { | ||
*Delay = confTest.Delay | ||
} | ||
if *buildDelay == 30*time.Second && confTest.BuildDelay != 0 { | ||
*buildDelay = confTest.BuildDelay | ||
} | ||
if len(*passThorughPorts) == 0 { | ||
*passThorughPorts = confTest.PassThroughPorts | ||
} | ||
|
@@ -188,6 +192,12 @@ func (t *Test) GetCmd() *cobra.Command { | |
return err | ||
} | ||
|
||
buildDelay, err := cmd.Flags().GetDuration("buildDelay") | ||
if err != nil { | ||
t.logger.Error("Failed to get the build-delay flag", zap.Error((err))) | ||
return err | ||
} | ||
|
||
apiTimeout, err := cmd.Flags().GetUint64("apiTimeout") | ||
if err != nil { | ||
t.logger.Error("Failed to get the apiTimeout flag", zap.Error((err))) | ||
|
@@ -215,7 +225,7 @@ func (t *Test) GetCmd() *cobra.Command { | |
globalNoise := make(models.GlobalNoise) | ||
testsetNoise := make(models.TestsetNoise) | ||
|
||
err = t.getTestConfig(&path, &proxyPort, &appCmd, &testSets, &appContainer, &networkName, &delay, &ports, &apiTimeout, &globalNoise, &testsetNoise, &coverageReportPath, &withCoverage, configPath) | ||
err = t.getTestConfig(&path, &proxyPort, &appCmd, &testSets, &appContainer, &networkName, &delay, &buildDelay, &ports, &apiTimeout, &globalNoise, &testsetNoise, &coverageReportPath, &withCoverage, configPath) | ||
if err != nil { | ||
if err == errFileNotFound { | ||
t.logger.Info("continuing without configuration file because file not found") | ||
|
@@ -227,7 +237,7 @@ func (t *Test) GetCmd() *cobra.Command { | |
if appCmd == "" { | ||
fmt.Println("Error: missing required -c flag or appCmd in config file") | ||
if isDockerCmd { | ||
fmt.Println("Example usage:\n", `keploy test -c "docker run -p 8080:808 --network myNetworkName myApplicationImageName" --delay 6\n`) | ||
fmt.Println("Example usage:\n", `keploy test -c "docker run -p 8080:8080 --network myNetworkName myApplicationImageName" --delay 6\n`) | ||
} | ||
fmt.Println("Example usage:\n", cmd.Example) | ||
|
||
|
@@ -237,7 +247,16 @@ func (t *Test) GetCmd() *cobra.Command { | |
if delay <= 5 { | ||
fmt.Printf("Warning: delay is set to %d seconds, incase your app takes more time to start use --delay to set custom delay\n", delay) | ||
if isDockerCmd { | ||
fmt.Println("Example usage:\n", `keploy test -c "docker run -p 8080:808 --network myNetworkName myApplicationImageName" --delay 6\n`) | ||
fmt.Println("Example usage:\n", `keploy test -c "docker run -p 8080:8080 --network myNetworkName myApplicationImageName" --delay 6\n`) | ||
} else { | ||
fmt.Println("Example usage:\n", cmd.Example) | ||
} | ||
} | ||
|
||
if isDockerCmd && buildDelay <= 30*time.Second { | ||
fmt.Printf("Warning: buildDelay is set to %d, incase your docker container takes more time to build use --buildDelay to set custom delay\n", buildDelay) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This warning should be printed only when there is docker command because we don't need the build-delay flag in case of native integration. |
||
if isDockerCmd { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No need to check for |
||
fmt.Println("Example usage:\n", `keploy test -c "docker-compose up --build" --buildDelay 35s\n`, "\nor\n", `keploy test -c "docker-compose up --build" --buildDelay 1m\n`) | ||
} else { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Only mention test command usage here. And the port forwarding in the docker command should have port There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sorry for the confusion, what does 'Only mention test command usage here. ' mean , Shall I remove the warning message 🤔 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sorry, I didn't notice. You don't need to remove the command or any warning message. Just fix the port forwarding. |
||
fmt.Println("Example usage:\n", cmd.Example) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since this There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
By default, do we assume that the docker environment is built when the user uses the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @IllTamer Whenever there is a docker env the |
||
} | ||
|
@@ -273,7 +292,7 @@ func (t *Test) GetCmd() *cobra.Command { | |
} | ||
if !hasContainerName && appContainer == "" { | ||
fmt.Println("Error: missing required --containerName flag or containerName in config file") | ||
fmt.Println("\nExample usage:\n", `keploy test -c "docker run -p 8080:808 --network myNetworkName myApplicationImageName" --delay 6`) | ||
fmt.Println("\nExample usage:\n", `keploy test -c "docker run -p 8080:8080 --network myNetworkName myApplicationImageName" --delay 6`) | ||
return errors.New("missing required --containerName flag or containerName in config file") | ||
} | ||
} | ||
|
@@ -293,6 +312,7 @@ func (t *Test) GetCmd() *cobra.Command { | |
AppNetwork: networkName, | ||
MongoPassword: mongoPassword, | ||
Delay: delay, | ||
BuildDelay: buildDelay, | ||
PassThroughPorts: ports, | ||
ApiTimeout: apiTimeout, | ||
ProxyPort: proxyPort, | ||
|
@@ -319,6 +339,8 @@ func (t *Test) GetCmd() *cobra.Command { | |
testCmd.Flags().StringP("networkName", "n", "", "Name of the application's docker network") | ||
testCmd.Flags().Uint64P("delay", "d", 5, "User provided time to run its application") | ||
|
||
testCmd.Flags().DurationP("buildDelay", "", 30*time.Second, "User provided time to wait docker container build") | ||
|
||
testCmd.Flags().Uint64("apiTimeout", 5, "User provided timeout for calling its application") | ||
|
||
testCmd.Flags().UintSlice("passThroughPorts", []uint{}, "Ports of Outgoing dependency calls to be ignored as mocks") | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please remove the other example here also. And have you tested your changes with the config file as well?