mirror of
https://github.com/opentofu/opentofu.git
synced 2025-02-25 18:45:20 -06:00
issue 966: different user agent for unit tests (#1279)
Signed-off-by: Shashwat Pandey <72958686+SypherSP@users.noreply.github.com>
This commit is contained in:
parent
0b6d8ba2a5
commit
96b7fce5d1
5
.github/workflows/checks.yml
vendored
5
.github/workflows/checks.yml
vendored
@ -9,7 +9,7 @@
|
||||
# The build.yml workflow includes some additional checks we run only for
|
||||
# already-merged changes to release branches and tags, as a compromise to
|
||||
# keep the PR feedback relatively fast. The intent is that checks.yml should
|
||||
# catch most problems but that build.yml might occasionally by the one to catch
|
||||
# catch most problems but that build.yml might occasionally be the one to catch
|
||||
# more esoteric situations, such as architecture-specific or OS-specific
|
||||
# misbehavior.
|
||||
|
||||
@ -36,6 +36,9 @@ jobs:
|
||||
name: "Unit Tests"
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
env:
|
||||
TF_APPEND_USER_AGENT: Integration-Test
|
||||
|
||||
steps:
|
||||
- name: "Fetch source code"
|
||||
uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3.5.3
|
||||
|
@ -10,12 +10,18 @@ import (
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"net/url"
|
||||
"os"
|
||||
"testing"
|
||||
|
||||
"github.com/opentofu/opentofu/version"
|
||||
)
|
||||
|
||||
func TestNew_userAgent(t *testing.T) {
|
||||
|
||||
appendUaVal := os.Getenv(appendUaEnvVar)
|
||||
os.Unsetenv(appendUaEnvVar)
|
||||
defer os.Setenv(appendUaEnvVar, appendUaVal)
|
||||
|
||||
var actualUserAgent string
|
||||
ts := httptest.NewServer(http.HandlerFunc(func(rw http.ResponseWriter, req *http.Request) {
|
||||
actualUserAgent = req.UserAgent()
|
||||
|
@ -7,12 +7,18 @@ package httpclient
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"testing"
|
||||
|
||||
"github.com/opentofu/opentofu/version"
|
||||
)
|
||||
|
||||
func TestUserAgentString_env(t *testing.T) {
|
||||
|
||||
appendUaVal := os.Getenv(appendUaEnvVar)
|
||||
os.Unsetenv(appendUaEnvVar)
|
||||
defer os.Setenv(appendUaEnvVar, appendUaVal)
|
||||
|
||||
expectedBase := fmt.Sprintf("%s/%s", DefaultApplicationName, version.Version)
|
||||
|
||||
for i, c := range []struct {
|
||||
@ -67,6 +73,11 @@ func TestUserAgentAppendViaEnvVar(t *testing.T) {
|
||||
}
|
||||
}
|
||||
func TestCustomUserAgentViaEnvVar(t *testing.T) {
|
||||
|
||||
appendUaVal := os.Getenv(appendUaEnvVar)
|
||||
os.Unsetenv(appendUaEnvVar)
|
||||
defer os.Setenv(appendUaEnvVar, appendUaVal)
|
||||
|
||||
testCases := []struct {
|
||||
envVarValue string
|
||||
}{
|
||||
|
Loading…
Reference in New Issue
Block a user