Skip to content

Commit

Permalink
allow modifying /etc/hosts on the proxy for testing (#11)
Browse files Browse the repository at this point in the history
  • Loading branch information
jakecoffman authored Oct 3, 2022
1 parent faee75d commit b7ed930
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 0 deletions.
1 change: 1 addition & 0 deletions cmd/dependabot/internal/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ var (
file string
cache string
debugging bool
extraHosts []string
output string
pullImages bool
volumes []string
Expand Down
2 changes: 2 additions & 0 deletions cmd/dependabot/internal/cmd/test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ var testCmd = &cobra.Command{
Creds: scenario.Input.Credentials,
Debug: debugging,
Expected: scenario.Output,
ExtraHosts: extraHosts,
Job: &scenario.Input.Job,
Output: output,
PullImages: pullImages,
Expand Down Expand Up @@ -83,5 +84,6 @@ func init() {
testCmd.Flags().BoolVar(&pullImages, "pull", true, "pull the image if it isn't present")
testCmd.Flags().BoolVar(&debugging, "debug", false, "run an interactive shell inside the updater")
testCmd.Flags().StringArrayVarP(&volumes, "volume", "v", nil, "mount volumes in Docker")
testCmd.Flags().StringArrayVar(&extraHosts, "extra-hosts", nil, "Docker extra hosts setting on the proxy")
testCmd.Flags().DurationVarP(&timeout, "timeout", "t", 0, "max time to run an update")
}
2 changes: 2 additions & 0 deletions cmd/dependabot/internal/cmd/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ var updateCmd = &cobra.Command{
Creds: input.Credentials,
Debug: debugging,
Expected: nil, // update subcommand doesn't use expectations
ExtraHosts: extraHosts,
Job: &input.Job,
Output: output,
PullImages: pullImages,
Expand Down Expand Up @@ -192,6 +193,7 @@ func init() {
updateCmd.Flags().BoolVar(&pullImages, "pull", true, "pull the image if it isn't present")
updateCmd.Flags().BoolVar(&debugging, "debug", false, "run an interactive shell inside the updater")
updateCmd.Flags().StringArrayVarP(&volumes, "volume", "v", nil, "mount volumes in Docker")
updateCmd.Flags().StringArrayVar(&extraHosts, "extra-hosts", nil, "Docker extra hosts setting on the proxy")
updateCmd.Flags().DurationVarP(&timeout, "timeout", "t", 0, "max time to run an update")
updateCmd.Flags().IntVar(&inputServerPort, "input-port", 0, "port to use for securely passing input to the updater")
}
1 change: 1 addition & 0 deletions internal/infra/proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ func NewProxy(ctx context.Context, cli *client.Client, params *RunParams, nets .
"host.docker.internal:host-gateway",
},
}
hostCfg.ExtraHosts = append(hostCfg.ExtraHosts, params.ExtraHosts...)
if params.CacheDir != "" {
_ = os.MkdirAll(params.CacheDir, 0744)
cacheDir, _ := filepath.Abs(params.CacheDir)
Expand Down
2 changes: 2 additions & 0 deletions internal/infra/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ type RunParams struct {
Timeout time.Duration
// TempDir is the path to use as the temporary directory.
TempDir string
// ExtraHosts adds /etc/hosts entries to the proxy for testing.
ExtraHosts []string
}

func Run(params RunParams) error {
Expand Down

0 comments on commit b7ed930

Please sign in to comment.