@@ -2,48 +2,56 @@ use serde_json::json;
22
33#[ test]
44fn test_tenant_id_functionality_in_production ( ) {
5- let function_name = std :: env :: var ( "TENANT_ID_TEST_FUNCTION" )
6- . expect ( "TENANT_ID_TEST_FUNCTION environment variable not set" ) ;
7-
5+ let function_name =
6+ std :: env :: var ( "TENANT_ID_TEST_FUNCTION" ) . expect ( "TENANT_ID_TEST_FUNCTION environment variable not set" ) ;
7+
88 // Test with tenant ID
99 let payload_with_tenant = json ! ( {
1010 "test" : "tenant_id_test" ,
1111 "message" : "Testing with tenant ID"
1212 } ) ;
13-
13+
1414 let output = std:: process:: Command :: new ( "aws" )
1515 . args ( [
16- "lambda" , "invoke" ,
17- "--function-name" , & function_name,
18- "--payload" , & payload_with_tenant. to_string ( ) ,
19- "--cli-binary-format" , "raw-in-base64-out" ,
20- "/tmp/tenant_response.json"
16+ "lambda" ,
17+ "invoke" ,
18+ "--function-name" ,
19+ & function_name,
20+ "--payload" ,
21+ & payload_with_tenant. to_string ( ) ,
22+ "--cli-binary-format" ,
23+ "raw-in-base64-out" ,
24+ "/tmp/tenant_response.json" ,
2125 ] )
2226 . output ( )
2327 . expect ( "Failed to invoke Lambda function" ) ;
24-
25- assert ! ( output. status. success( ) , "Lambda invocation failed: {}" ,
26- String :: from_utf8_lossy( & output. stderr) ) ;
27-
28+
29+ assert ! (
30+ output. status. success( ) ,
31+ "Lambda invocation failed: {}" ,
32+ String :: from_utf8_lossy( & output. stderr)
33+ ) ;
34+
2835 // Read and verify response
29- let response = std:: fs:: read_to_string ( "/tmp/tenant_response.json" )
30- . expect ( "Failed to read response file" ) ;
31-
32- let response_json: serde_json:: Value = serde_json:: from_str ( & response)
33- . expect ( "Failed to parse response JSON" ) ;
34-
36+ let response = std:: fs:: read_to_string ( "/tmp/tenant_response.json" ) . expect ( "Failed to read response file" ) ;
37+
38+ let response_json: serde_json:: Value = serde_json:: from_str ( & response) . expect ( "Failed to parse response JSON" ) ;
39+
3540 // Verify the function executed successfully
3641 assert_eq ! ( response_json[ "statusCode" ] , 200 ) ;
37-
42+
3843 // Parse the body to check tenant_id field exists (even if null)
39- let body: serde_json:: Value = serde_json:: from_str (
40- response_json[ "body" ] . as_str ( ) . expect ( "Body should be a string" )
41- ) . expect ( "Failed to parse body JSON" ) ;
42-
43- assert ! ( body. get( "tenant_id" ) . is_some( ) , "tenant_id field should be present in response" ) ;
44+ let body: serde_json:: Value =
45+ serde_json:: from_str ( response_json[ "body" ] . as_str ( ) . expect ( "Body should be a string" ) )
46+ . expect ( "Failed to parse body JSON" ) ;
47+
48+ assert ! (
49+ body. get( "tenant_id" ) . is_some( ) ,
50+ "tenant_id field should be present in response"
51+ ) ;
4452 assert ! ( body. get( "request_id" ) . is_some( ) , "request_id should be present" ) ;
4553 assert_eq ! ( body[ "message" ] , "Tenant ID test successful" ) ;
46-
54+
4755 println ! ( "✅ Tenant ID production test passed" ) ;
4856 println ! ( "Response: {}" , serde_json:: to_string_pretty( & response_json) . unwrap( ) ) ;
4957}
0 commit comments