Skip to content

Commit

Permalink
Fixed mock mode behavior with flags
Browse files Browse the repository at this point in the history
Mock mode was not being picked up correctly when using flags, I failed during a live demo - a slap on the wrist for quobix.

Signed-off-by: quobix <dave@quobix.com>
  • Loading branch information
daveshanley committed Sep 14, 2023
1 parent 446bb8d commit 4bd7763
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 21 deletions.
11 changes: 9 additions & 2 deletions cmd/booted_message.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,15 @@ func bootedMessage(wiretapConfig *shared.WiretapConfiguration) {
Println(panels)

pterm.Println()
pterm.Info.Printf("API Gateway is now proxying all traffic to '%s'\n",
pterm.LightMagenta(wiretapConfig.RedirectURL))
if wiretapConfig.MockMode {
pterm.Info.Printf("Ⓜ️ wiretap is not proxying any traffic, all responses are %s.\n",
pterm.LightMagenta("generated mocks/simulations"))

} else {
pterm.Info.Printf("wiretap is now proxying all traffic to '%s'\n",
pterm.LightMagenta(wiretapConfig.RedirectURL))
}

pterm.Println()
}
}, nil)
Expand Down
50 changes: 31 additions & 19 deletions cmd/root_command.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,10 +154,19 @@ var (
if config.Spec != "" {
spec = config.Spec
}
if mockMode {
if !config.MockMode {
config.MockMode = true
}
}

} else {

pterm.Info.Println("No wiretap configuration located. Using defaults")
config.StaticIndex = staticIndex
if mockMode {
config.MockMode = true
}
}

if spec == "" {
Expand All @@ -178,33 +187,36 @@ var (
return nil
}

if redirectURL == "" {
if !mockMode && redirectURL == "" {
pterm.Println()
pterm.Error.Println("No redirect URL provided. " +
"Please provide a URL to redirect API traffic to using the --url or -u flags.")
pterm.Println()
return nil
}

parsedURL, e := url.Parse(redirectURL)
if e != nil {
pterm.Println()
pterm.Error.Printf("URL is not valid. "+
"Please provide a valid URL to redirect to. %s cannot be parsed\n\n", redirectURL)
pterm.Println()
return nil
}
if parsedURL.Scheme == "" || parsedURL.Host == "" {
pterm.Println()
pterm.Error.Printf("URL is not valid. "+
"Please provide a valid URL to redirect to. %s cannot be parsed\n\n", redirectURL)
pterm.Println()
return nil
if redirectURL != "" {

parsedURL, e := url.Parse(redirectURL)
if e != nil {
pterm.Println()
pterm.Error.Printf("URL is not valid. "+
"Please provide a valid URL to redirect to. %s cannot be parsed\n\n", redirectURL)
pterm.Println()
return nil
}
if parsedURL.Scheme == "" || parsedURL.Host == "" {
pterm.Println()
pterm.Error.Printf("URL is not valid. "+
"Please provide a valid URL to redirect to. %s cannot be parsed\n\n", redirectURL)
pterm.Println()
return nil
}
redirectHost = parsedURL.Hostname()
redirectPort = parsedURL.Port()
redirectScheme = parsedURL.Scheme
redirectBasePath = parsedURL.Path
}
redirectHost = parsedURL.Hostname()
redirectPort = parsedURL.Port()
redirectScheme = parsedURL.Scheme
redirectBasePath = parsedURL.Path

if spec != "" {
config.Contract = spec
Expand Down

0 comments on commit 4bd7763

Please sign in to comment.