@@ -55,31 +55,18 @@ func TestHandshakeProse(t *testing.T) {
5555 return elems
5656 }
5757
58- const (
59- envVarAWSExecutionEnv = "AWS_EXECUTION_ENV"
60- envVarAWSRegion = "AWS_REGION"
61- envVarAWSLambdaFunctionMemorySize = "AWS_LAMBDA_FUNCTION_MEMORY_SIZE"
62- envVarFunctionsWorkerRuntime = "FUNCTIONS_WORKER_RUNTIME"
63- envVarKService = "K_SERVICE"
64- envVarFunctionMemoryMB = "FUNCTION_MEMORY_MB"
65- envVarFunctionTimeoutSec = "FUNCTION_TIMEOUT_SEC"
66- envVarFunctionRegion = "FUNCTION_REGION"
67- envVarVercel = "VERCEL"
68- envVarVercelRegion = "VERCEL_REGION"
69- )
70-
7158 // Reset the environment variables to avoid environment namespace
7259 // collision.
73- t .Setenv (envVarAWSExecutionEnv , "" )
74- t .Setenv (envVarFunctionsWorkerRuntime , "" )
75- t .Setenv (envVarKService , "" )
76- t .Setenv (envVarVercel , "" )
77- t .Setenv (envVarAWSRegion , "" )
78- t .Setenv (envVarAWSLambdaFunctionMemorySize , "" )
79- t .Setenv (envVarFunctionMemoryMB , "" )
80- t .Setenv (envVarFunctionTimeoutSec , "" )
81- t .Setenv (envVarFunctionRegion , "" )
82- t .Setenv (envVarVercelRegion , "" )
60+ t .Setenv ("AWS_EXECUTION_ENV" , "" )
61+ t .Setenv ("FUNCTIONS_WORKER_RUNTIME" , "" )
62+ t .Setenv ("K_SERVICE" , "" )
63+ t .Setenv ("VERCEL" , "" )
64+ t .Setenv ("AWS_REGION" , "" )
65+ t .Setenv ("AWS_LAMBDA_FUNCTION_MEMORY_SIZE" , "" )
66+ t .Setenv ("FUNCTION_MEMORY_MB" , "" )
67+ t .Setenv ("FUNCTION_TIMEOUT_SEC" , "" )
68+ t .Setenv ("FUNCTION_REGION" , "" )
69+ t .Setenv ("VERCEL_REGION" , "" )
8370
8471 for _ , test := range []struct {
8572 name string
@@ -89,9 +76,9 @@ func TestHandshakeProse(t *testing.T) {
8976 {
9077 name : "1. valid AWS" ,
9178 env : map [string ]string {
92- envVarAWSExecutionEnv : "AWS_Lambda_java8" ,
93- envVarAWSRegion : "us-east-2" ,
94- envVarAWSLambdaFunctionMemorySize : "1024" ,
79+ "AWS_EXECUTION_ENV" : "AWS_Lambda_java8" ,
80+ "AWS_REGION" : "us-east-2" ,
81+ "AWS_LAMBDA_FUNCTION_MEMORY_SIZE" : "1024" ,
9582 },
9683 want : clientMetadata (bson.D {
9784 {Key : "name" , Value : "aws.lambda" },
@@ -102,7 +89,7 @@ func TestHandshakeProse(t *testing.T) {
10289 {
10390 name : "2. valid Azure" ,
10491 env : map [string ]string {
105- envVarFunctionsWorkerRuntime : "node" ,
92+ "FUNCTIONS_WORKER_RUNTIME" : "node" ,
10693 },
10794 want : clientMetadata (bson.D {
10895 {Key : "name" , Value : "azure.func" },
@@ -111,10 +98,10 @@ func TestHandshakeProse(t *testing.T) {
11198 {
11299 name : "3. valid GCP" ,
113100 env : map [string ]string {
114- envVarKService : "servicename" ,
115- envVarFunctionMemoryMB : "1024" ,
116- envVarFunctionTimeoutSec : "60" ,
117- envVarFunctionRegion : "us-central1" ,
101+ "K_SERVICE" : "servicename" ,
102+ "FUNCTION_MEMORY_MB" : "1024" ,
103+ "FUNCTION_TIMEOUT_SEC" : "60" ,
104+ "FUNCTION_REGION" : "us-central1" ,
118105 },
119106 want : clientMetadata (bson.D {
120107 {Key : "name" , Value : "gcp.func" },
@@ -126,8 +113,8 @@ func TestHandshakeProse(t *testing.T) {
126113 {
127114 name : "4. valid Vercel" ,
128115 env : map [string ]string {
129- envVarVercel : "1" ,
130- envVarVercelRegion : "cdg1" ,
116+ "VERCEL" : "1" ,
117+ "VERCEL_REGION" : "cdg1" ,
131118 },
132119 want : clientMetadata (bson.D {
133120 {Key : "name" , Value : "vercel" },
@@ -137,16 +124,16 @@ func TestHandshakeProse(t *testing.T) {
137124 {
138125 name : "5. invalid multiple providers" ,
139126 env : map [string ]string {
140- envVarAWSExecutionEnv : "AWS_Lambda_java8" ,
141- envVarFunctionsWorkerRuntime : "node" ,
127+ "AWS_EXECUTION_ENV" : "AWS_Lambda_java8" ,
128+ "FUNCTIONS_WORKER_RUNTIME" : "node" ,
142129 },
143130 want : clientMetadata (nil ),
144131 },
145132 {
146133 name : "6. invalid long string" ,
147134 env : map [string ]string {
148- envVarAWSExecutionEnv : "AWS_Lambda_java8" ,
149- envVarAWSRegion : func () string {
135+ "AWS_EXECUTION_ENV" : "AWS_Lambda_java8" ,
136+ "AWS_REGION" : func () string {
150137 var s string
151138 for i := 0 ; i < 512 ; i ++ {
152139 s += "a"
@@ -161,8 +148,8 @@ func TestHandshakeProse(t *testing.T) {
161148 {
162149 name : "7. invalid wrong types" ,
163150 env : map [string ]string {
164- envVarAWSExecutionEnv : "AWS_Lambda_java8" ,
165- envVarAWSLambdaFunctionMemorySize : "big" ,
151+ "AWS_EXECUTION_ENV" : "AWS_Lambda_java8" ,
152+ "AWS_LAMBDA_FUNCTION_MEMORY_SIZE" : "big" ,
166153 },
167154 want : clientMetadata (bson.D {
168155 {Key : "name" , Value : "aws.lambda" },
@@ -171,7 +158,7 @@ func TestHandshakeProse(t *testing.T) {
171158 {
172159 name : "8. Invalid - AWS_EXECUTION_ENV does not start with \" AWS_Lambda_\" " ,
173160 env : map [string ]string {
174- envVarAWSExecutionEnv : "EC2" ,
161+ "AWS_EXECUTION_ENV" : "EC2" ,
175162 },
176163 want : clientMetadata (nil ),
177164 },
@@ -188,32 +175,27 @@ func TestHandshakeProse(t *testing.T) {
188175 require .NoError (mt , err , "Ping error: %v" , err )
189176
190177 messages := mt .GetProxiedMessages ()
178+ handshakeMessage := messages [:1 ][0 ]
191179
192- // First two messages are handshake messages
193- for idx , pair := range messages [:2 ] {
194- hello := handshake .LegacyHello
195- // Expect "hello" command name with API version.
196- if os .Getenv ("REQUIRE_API_VERSION" ) == "true" {
197- hello = "hello"
198- }
199-
200- assert .Equal (mt , pair .CommandName , hello , "expected and actual command name at index %d are different" , idx )
180+ hello := handshake .LegacyHello
181+ if os .Getenv ("REQUIRE_API_VERSION" ) == "true" {
182+ hello = "hello"
183+ }
201184
202- sent := pair . Sent
185+ assert . Equal ( mt , hello , handshakeMessage . CommandName )
203186
204- // Lookup the "client" field in the command document.
205- clientVal , err := sent .Command .LookupErr ("client" )
206- require .NoError (mt , err , "expected command %s at index %d to contain client field" , sent . Command , idx )
187+ // Lookup the "client" field in the command document.
188+ clientVal , err := handshakeMessage . Sent .Command .LookupErr ("client" )
189+ require .NoError (mt , err , "expected command %s to contain client field" , handshakeMessage . Sent . Command )
207190
208- got , ok := clientVal .DocumentOK ()
209- require .True (mt , ok , "expected client field to be a document, got %s" , clientVal .Type )
191+ got , ok := clientVal .DocumentOK ()
192+ require .True (mt , ok , "expected client field to be a document, got %s" , clientVal .Type )
210193
211- wantBytes , err := bson .Marshal (test .want )
212- require .NoError (mt , err , "error marshaling want document: %v" , err )
194+ wantBytes , err := bson .Marshal (test .want )
195+ require .NoError (mt , err , "error marshaling want document: %v" , err )
213196
214- want := bsoncore .Document (wantBytes )
215- assert .Equal (mt , want , got , "want: %v, got: %v" , want , got )
216- }
197+ want := bsoncore .Document (wantBytes )
198+ assert .Equal (mt , want , got , "want: %v, got: %v" , want , got )
217199 })
218200 }
219201}
0 commit comments