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

refactor: logs in record and test commands #1228

Merged
merged 3 commits into from
Dec 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions cmd/record.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ func readRecordConfig(configPath string) (*models.Record, error) {
return &doc.Record, nil
}

var filters = *&models.Filters{}
var filters = models.Filters{}

func (t *Record) GetRecordConfig(path *string, proxyPort *uint32, appCmd *string, appContainer, networkName *string, Delay *uint64, buildDelay *time.Duration, passThroughPorts *[]uint, configPath string) error {
configFilePath := filepath.Join(configPath, "keploy-config.yaml")
Expand Down Expand Up @@ -162,11 +162,11 @@ func (r *Record) GetCmd() *cobra.Command {
}

if appCmd == "" {
fmt.Println("Error: missing required -c flag or appCmd in config file")
r.logger.Error("missing required -c flag or appCmd in config file")
if isDockerCmd {
fmt.Println("Example usage:\n", `keploy record -c "docker run -p 8080:8080 --network myNetworkName myApplicationImageName" --delay 6\n`)
r.logger.Info(`Example usage: keploy record -c "docker run -p 8080:8080 --network myNetworkName myApplicationImageName" --delay 6`)
} else {
fmt.Println("Example usage:\n", cmd.Example)
r.logger.Info(fmt.Sprintf("Example usage:%s", cmd.Example))
}
return errors.New("missing required -c flag or appCmd in config file")
}
Expand All @@ -189,8 +189,8 @@ func (r *Record) GetCmd() *cobra.Command {
}

if isDockerCmd && buildDelay <= 30*time.Second {
fmt.Printf("Warning: buildDelay is set to %v, incase your docker container takes more time to build use --buildDelay to set custom delay\n", buildDelay)
fmt.Println("Example usage:\n", `keploy record -c "docker-compose up --build" --buildDelay 35s\n`, "\nor\n", `keploy record -c "docker-compose up --build" --buildDelay 1m\n`)
r.logger.Warn(fmt.Sprintf("buildDelay is set to %v, incase your docker container takes more time to build use --buildDelay to set custom delay", buildDelay))
r.logger.Info(`Example usage: keploy record -c "docker-compose up --build" --buildDelay 35s`)
}

path += "/keploy"
Expand All @@ -203,8 +203,8 @@ func (r *Record) GetCmd() *cobra.Command {
hasContainerName = true
}
if !hasContainerName && appContainer == "" {
fmt.Println("Error: missing required --containerName flag or containerName in config file")
fmt.Println("\nExample usage:\n", `keploy record -c "docker run -p 8080:8080 --network myNetworkName myApplicationImageName" --delay 6`)
r.logger.Error("Couldn't find containerName")
r.logger.Info(`Example usage: keploy record -c "docker run -p 8080:8080 --network myNetworkName myApplicationImageName" --delay 6`)
return errors.New("missing required --containerName flag or containerName in config file")
}
}
Expand Down
22 changes: 11 additions & 11 deletions cmd/test.go
Original file line number Diff line number Diff line change
Expand Up @@ -203,27 +203,27 @@ func (t *Test) GetCmd() *cobra.Command {
}

if appCmd == "" {
fmt.Println("Error: missing required -c flag or appCmd in config file")
t.logger.Error("Couldn't find appCmd")
if isDockerCmd {
fmt.Println("Example usage:\n", `keploy test -c "docker run -p 8080:8080 --network myNetworkName myApplicationImageName" --delay 6\n`)
t.logger.Info(`Example usage: keploy test -c "docker run -p 8080:8080 --network myNetworkName myApplicationImageName" --delay 6`)
} else {
t.logger.Info(fmt.Sprintf("Example usage: %s", cmd.Example))
}
fmt.Println("Example usage:\n", cmd.Example)

return errors.New("missing required -c flag or appCmd in config file")
}

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)
t.logger.Warn(fmt.Sprintf("Delay is set to %d seconds, incase your app takes more time to start use --delay to set custom delay", delay))
if isDockerCmd {
fmt.Println("Example usage:\n", `keploy test -c "docker run -p 8080:8080 --network myNetworkName myApplicationImageName" --delay 6\n`)
t.logger.Info(`Example usage: keploy test -c "docker run -p 8080:8080 --network myNetworkName myApplicationImageName" --delay 6`)
} else {
fmt.Println("Example usage:\n", cmd.Example)
t.logger.Info("Example usage: " + cmd.Example)
}
}

if isDockerCmd && buildDelay <= 30*time.Second {
fmt.Printf("Warning: buildDelay is set to %v, incase your docker container takes more time to build use --buildDelay to set custom delay\n", buildDelay)
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`)
t.logger.Warn(fmt.Sprintf("buildDelay is set to %v, incase your docker container takes more time to build use --buildDelay to set custom delay", buildDelay))
t.logger.Info(`Example usage:keploy test -c "docker-compose up --build" --buildDelay 35s`)
}

//if user provides relative path
Expand Down Expand Up @@ -255,8 +255,8 @@ func (t *Test) GetCmd() *cobra.Command {
hasContainerName = true
}
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:8080 --network myNetworkName myApplicationImageName" --delay 6`)
t.logger.Error("Couldn't find containerName")
t.logger.Info(`Example usage: 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")
}
}
Expand Down
Loading