-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Janos <[email protected]>
- Loading branch information
Janos
committed
Aug 12, 2024
1 parent
36ea59e
commit e328c84
Showing
3 changed files
with
73 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
// Copyright (c) The OpenTofu Authors | ||
// SPDX-License-Identifier: MPL-2.0 | ||
// Copyright (c) 2023 HashiCorp, Inc. | ||
// SPDX-License-Identifier: MPL-2.0 | ||
|
||
package tofutestutils | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/opentofu/tofutestutils/testproxy" | ||
) | ||
|
||
// HTTPProxy starts an HTTP proxy and returns the connection details as a result. | ||
func HTTPProxy(t *testing.T, options ...testproxy.HTTPOption) testproxy.HTTPService { | ||
return testproxy.HTTP(t, options...) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
# HTTP proxy | ||
|
||
This package implements a full HTTP proxy for testing purposes. You can use this package to test if a proxy configuration handles settings correctly. The simplest version to create a proxy is as follows: | ||
|
||
```go | ||
package your_test | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/opentofu/tofutestutils/testproxy" | ||
) | ||
|
||
func TestMyApp(t *testing.T) { | ||
proxy := testproxy.HTTP(t) | ||
|
||
t.Setenv("http_proxy", proxy.HTTPProxy().String()) | ||
t.Setenv("https_proxy", proxy.HTTPSProxy().String()) | ||
|
||
// Proxy-using code here | ||
} | ||
``` | ||
|
||
> [!NOTE] | ||
> You can use the HTTP proxy for HTTPS URLs. This is because the connection to the proxy is not necessarily encrypted, the proxy can perform certificate verification. If you use the `HTTPSProxy()` call, you should configure your HTTP clients to accept the certificate presented in the `proxy.CACert()` function. | ||
You can customize the proxy behavior and force connections to go to a specific endpoint. For details, please check [the documentation for this package](https://pkg.go.dev/github.com/opentofu/tofutestutils/testproxy). |