@@ -55,31 +55,18 @@ func TestHandshakeProse(t *testing.T) {
55
55
return elems
56
56
}
57
57
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
-
71
58
// Reset the environment variables to avoid environment namespace
72
59
// 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" , "" )
83
70
84
71
for _ , test := range []struct {
85
72
name string
@@ -89,9 +76,9 @@ func TestHandshakeProse(t *testing.T) {
89
76
{
90
77
name : "1. valid AWS" ,
91
78
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" ,
95
82
},
96
83
want : clientMetadata (bson.D {
97
84
{Key : "name" , Value : "aws.lambda" },
@@ -102,7 +89,7 @@ func TestHandshakeProse(t *testing.T) {
102
89
{
103
90
name : "2. valid Azure" ,
104
91
env : map [string ]string {
105
- envVarFunctionsWorkerRuntime : "node" ,
92
+ "FUNCTIONS_WORKER_RUNTIME" : "node" ,
106
93
},
107
94
want : clientMetadata (bson.D {
108
95
{Key : "name" , Value : "azure.func" },
@@ -111,10 +98,10 @@ func TestHandshakeProse(t *testing.T) {
111
98
{
112
99
name : "3. valid GCP" ,
113
100
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" ,
118
105
},
119
106
want : clientMetadata (bson.D {
120
107
{Key : "name" , Value : "gcp.func" },
@@ -126,8 +113,8 @@ func TestHandshakeProse(t *testing.T) {
126
113
{
127
114
name : "4. valid Vercel" ,
128
115
env : map [string ]string {
129
- envVarVercel : "1" ,
130
- envVarVercelRegion : "cdg1" ,
116
+ "VERCEL" : "1" ,
117
+ "VERCEL_REGION" : "cdg1" ,
131
118
},
132
119
want : clientMetadata (bson.D {
133
120
{Key : "name" , Value : "vercel" },
@@ -137,16 +124,16 @@ func TestHandshakeProse(t *testing.T) {
137
124
{
138
125
name : "5. invalid multiple providers" ,
139
126
env : map [string ]string {
140
- envVarAWSExecutionEnv : "AWS_Lambda_java8" ,
141
- envVarFunctionsWorkerRuntime : "node" ,
127
+ "AWS_EXECUTION_ENV" : "AWS_Lambda_java8" ,
128
+ "FUNCTIONS_WORKER_RUNTIME" : "node" ,
142
129
},
143
130
want : clientMetadata (nil ),
144
131
},
145
132
{
146
133
name : "6. invalid long string" ,
147
134
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 {
150
137
var s string
151
138
for i := 0 ; i < 512 ; i ++ {
152
139
s += "a"
@@ -161,8 +148,8 @@ func TestHandshakeProse(t *testing.T) {
161
148
{
162
149
name : "7. invalid wrong types" ,
163
150
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" ,
166
153
},
167
154
want : clientMetadata (bson.D {
168
155
{Key : "name" , Value : "aws.lambda" },
@@ -171,7 +158,7 @@ func TestHandshakeProse(t *testing.T) {
171
158
{
172
159
name : "8. Invalid - AWS_EXECUTION_ENV does not start with \" AWS_Lambda_\" " ,
173
160
env : map [string ]string {
174
- envVarAWSExecutionEnv : "EC2" ,
161
+ "AWS_EXECUTION_ENV" : "EC2" ,
175
162
},
176
163
want : clientMetadata (nil ),
177
164
},
@@ -188,32 +175,27 @@ func TestHandshakeProse(t *testing.T) {
188
175
require .NoError (mt , err , "Ping error: %v" , err )
189
176
190
177
messages := mt .GetProxiedMessages ()
178
+ handshakeMessage := messages [:1 ][0 ]
191
179
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
+ }
201
184
202
- sent := pair . Sent
185
+ assert . Equal ( mt , hello , handshakeMessage . CommandName )
203
186
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 )
207
190
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 )
210
193
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 )
213
196
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 )
217
199
})
218
200
}
219
201
}
0 commit comments