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:
Shashwat Pandey 2024-02-22 14:15:06 +05:30 committed by GitHub
parent 0b6d8ba2a5
commit 96b7fce5d1
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 21 additions and 1 deletions

View File

@ -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

View File

@ -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()

View File

@ -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
}{