-
-
Notifications
You must be signed in to change notification settings - Fork 406
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 5 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, 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, 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 | ||
} | ||
|
@@ -174,6 +178,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))) | ||
|
@@ -201,7 +211,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, configPath) | ||
err = t.getTestConfig(&path, &proxyPort, &appCmd, &testSets, &appContainer, &networkName, &delay, &buildDelay, &ports, &apiTimeout, &globalNoise, &testsetNoise, configPath) | ||
if err != nil { | ||
if err == errFileNotFound { | ||
t.logger.Info("continuing without configuration file because file not found") | ||
|
@@ -229,6 +239,15 @@ func (t *Test) GetCmd() *cobra.Command { | |
} | ||
} | ||
|
||
if buildDelay <= time.Duration(30)*time.Second { | ||
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. The same if check should be in the record command as well. And don't mention the example usage of record in the test command. It should be in the record command. |
||
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 run -p 8080:808 --network myNetworkName myApplicationImageName" --buildDelay 35s\n`, "\nor\n", `keploy test -c "docker run -p 8080:808 --network myNetworkName myApplicationImageName" --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 |
||
} | ||
} | ||
|
||
//if user provides relative path | ||
if len(path) > 0 && path[0] != '/' { | ||
absPath, err := filepath.Abs(path) | ||
|
@@ -279,6 +298,7 @@ func (t *Test) GetCmd() *cobra.Command { | |
AppNetwork: networkName, | ||
MongoPassword: mongoPassword, | ||
Delay: delay, | ||
BuildDelay: buildDelay, | ||
PassThroughPorts: ports, | ||
ApiTimeout: apiTimeout, | ||
ProxyPort: proxyPort, | ||
|
@@ -303,6 +323,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.
You can remove this code since there is no build-delay in the serve command. So no need to check for this error.