From 2e8d9340160224d36fd555eaf8837240a7e239a7 Mon Sep 17 00:00:00 2001 From: Joel Ferrier Date: Thu, 1 Apr 2021 16:22:52 -0700 Subject: [PATCH] google: Use bytes.Buffer for go 1.9 compatability Update test cases to use const test data file references. Change-Id: Ic08b6de5a84db7b2ae2c649ee676c5a2c13f4227 Reviewed-on: https://go-review.googlesource.com/c/oauth2/+/306749 Reviewed-by: Cody Oss Trust: Cody Oss Trust: Tyler Bui-Palsulich Run-TryBot: Cody Oss TryBot-Result: Go Bot --- google/internal/externalaccount/aws.go | 3 ++- google/internal/externalaccount/basecredentials_test.go | 7 ++++++- google/internal/externalaccount/filecredsource_test.go | 6 +++--- 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/google/internal/externalaccount/aws.go b/google/internal/externalaccount/aws.go index 2f078f7..fbcefb4 100644 --- a/google/internal/externalaccount/aws.go +++ b/google/internal/externalaccount/aws.go @@ -5,6 +5,7 @@ package externalaccount import ( + "bytes" "context" "crypto/hmac" "crypto/sha256" @@ -127,7 +128,7 @@ func canonicalHeaders(req *http.Request) (string, string) { } sort.Strings(headers) - var fullHeaders strings.Builder + var fullHeaders bytes.Buffer for _, header := range headers { headerValue := strings.Join(lowerCaseHeaders[header], ",") fullHeaders.WriteString(header) diff --git a/google/internal/externalaccount/basecredentials_test.go b/google/internal/externalaccount/basecredentials_test.go index 78a1137..1ebb227 100644 --- a/google/internal/externalaccount/basecredentials_test.go +++ b/google/internal/externalaccount/basecredentials_test.go @@ -13,8 +13,13 @@ import ( "time" ) +const ( + textBaseCredPath = "testdata/3pi_cred.txt" + jsonBaseCredPath = "testdata/3pi_cred.json" +) + var testBaseCredSource = CredentialSource{ - File: "./testdata/3pi_cred.txt", + File: textBaseCredPath, Format: format{Type: fileTypeText}, } diff --git a/google/internal/externalaccount/filecredsource_test.go b/google/internal/externalaccount/filecredsource_test.go index ebd2bb7..553830d 100644 --- a/google/internal/externalaccount/filecredsource_test.go +++ b/google/internal/externalaccount/filecredsource_test.go @@ -28,14 +28,14 @@ func TestRetrieveFileSubjectToken(t *testing.T) { { name: "UntypedFileSource", cs: CredentialSource{ - File: "./testdata/3pi_cred.txt", + File: textBaseCredPath, }, want: "street123", }, { name: "TextFileSource", cs: CredentialSource{ - File: "./testdata/3pi_cred.txt", + File: textBaseCredPath, Format: format{Type: fileTypeText}, }, want: "street123", @@ -43,7 +43,7 @@ func TestRetrieveFileSubjectToken(t *testing.T) { { name: "JSONFileSource", cs: CredentialSource{ - File: "./testdata/3pi_cred.json", + File: jsonBaseCredPath, Format: format{Type: fileTypeJSON, SubjectTokenFieldName: "SubjToken"}, }, want: "321road",