Skip to content

Commit 07c3e66

Browse files
committed
Update SDKVersion constant to "0.1.21" in version.go
1 parent afba4a8 commit 07c3e66

File tree

4 files changed

+16
-23
lines changed

4 files changed

+16
-23
lines changed

headers/headers.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"github.com/deploymenttheory/go-api-http-client/apiintegrations/apihandler"
1010
"github.com/deploymenttheory/go-api-http-client/authenticationhandler"
1111
"github.com/deploymenttheory/go-api-http-client/headers/redact"
12+
"github.com/deploymenttheory/go-api-http-client/version"
1213

1314
"github.com/deploymenttheory/go-api-http-client/logger"
1415
"go.uber.org/zap"
@@ -97,6 +98,11 @@ func SetCustomHeader(req *http.Request, headerName, headerValue string) {
9798
req.Header.Set(headerName, headerValue)
9899
}
99100

101+
// SetUserAgentHeader sets the User-Agent header for an HTTP request.
102+
func SetUserAgentHeader() string {
103+
return fmt.Sprintf("%s/%s", version.UserAgentBase, version.SDKVersion)
104+
}
105+
100106
// SetRequestHeaders sets the necessary HTTP headers for a given request using the APIHandler to determine the required headers.
101107
func (h *HeaderHandler) SetRequestHeaders(endpoint string) {
102108
// Retrieve the standard headers required for the request

headers/headers_test.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,13 @@
22
package headers
33

44
import (
5+
"fmt"
56
"net/http"
67
"net/http/httptest"
78
"testing"
89

910
"github.com/deploymenttheory/go-api-http-client/authenticationhandler"
11+
"github.com/deploymenttheory/go-api-http-client/version"
1012
"github.com/stretchr/testify/assert"
1113
)
1214

@@ -127,6 +129,14 @@ func TestSetCustomHeader(t *testing.T) {
127129
assert.Equal(t, headerValue, req.Header.Get(headerName), "Custom header should be correctly set")
128130
}
129131

132+
// TestSetUserAgentHeader verifies that the SetUserAgentHeader function returns the expected user agent string
133+
func TestSetUserAgentHeader(t *testing.T) {
134+
expectedUserAgent := fmt.Sprintf("%s/%s", version.UserAgentBase, version.SDKVersion)
135+
userAgent := SetUserAgentHeader()
136+
137+
assert.Equal(t, expectedUserAgent, userAgent, "User agent string should match expected format")
138+
}
139+
130140
// TestSetRequestHeaders verifies that standard headers, including a custom Authorization header,
131141
// are set correctly on the HTTP request based on headers provided by a mock APIHandler.
132142
// TODO need to implement MockAPIHandler

version/version.go

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,7 @@
11
// version.go
22
package version
33

4-
import "fmt"
5-
64
const (
75
SDKVersion = "0.1.21"
86
UserAgentBase = "go-api-http-client"
97
)
10-
11-
func GetUserAgentHeader() string {
12-
return fmt.Sprintf("%s/%s", UserAgentBase, SDKVersion)
13-
}

version/version_test.go

Lines changed: 0 additions & 17 deletions
This file was deleted.

0 commit comments

Comments
 (0)