@@ -59,54 +59,51 @@ impl ResourceDetector for LambdaResourceDetector {
59
59
mod tests {
60
60
use super :: * ;
61
61
use sealed_test:: prelude:: * ;
62
- use std:: env:: { remove_var, set_var} ;
63
62
64
63
#[ sealed_test]
65
64
fn test_aws_lambda_detector ( ) {
66
- set_var ( AWS_LAMBDA_FUNCTION_NAME_ENV_VAR , "my-lambda-function" ) ;
67
- set_var ( AWS_REGION_ENV_VAR , "eu-west-3" ) ;
68
- set_var ( AWS_LAMBDA_FUNCTION_VERSION_ENV_VAR , "$LATEST" ) ;
69
- set_var (
70
- AWS_LAMBDA_LOG_STREAM_NAME_ENV_VAR ,
71
- "2023/01/01/[$LATEST]5d1edb9e525d486696cf01a3503487bc" ,
72
- ) ;
73
- set_var ( AWS_LAMBDA_MEMORY_LIMIT_ENV_VAR , "128" ) ;
74
- set_var (
75
- AWS_LAMBDA_LOG_GROUP_NAME_ENV_VAR ,
76
- "/aws/lambda/my-lambda-function" ,
77
- ) ;
78
-
79
- let expected = Resource :: builder_empty ( )
80
- . with_attributes ( [
81
- KeyValue :: new ( semconv:: resource:: CLOUD_PROVIDER , "aws" ) ,
82
- KeyValue :: new ( semconv:: resource:: CLOUD_REGION , "eu-west-3" ) ,
83
- KeyValue :: new (
84
- semconv:: resource:: FAAS_INSTANCE ,
85
- "2023/01/01/[$LATEST]5d1edb9e525d486696cf01a3503487bc" ,
65
+ temp_env:: with_vars (
66
+ [
67
+ ( AWS_LAMBDA_FUNCTION_NAME_ENV_VAR , Some ( "my-lambda-function" ) ) ,
68
+ ( AWS_REGION_ENV_VAR , Some ( "eu-west-3" ) ) ,
69
+ ( AWS_LAMBDA_FUNCTION_VERSION_ENV_VAR , Some ( "$LATEST" ) ) ,
70
+ (
71
+ AWS_LAMBDA_LOG_STREAM_NAME_ENV_VAR ,
72
+ Some ( "2023/01/01/[$LATEST]5d1edb9e525d486696cf01a3503487bc" ) ,
86
73
) ,
87
- KeyValue :: new ( semconv:: resource:: FAAS_NAME , "my-lambda-function" ) ,
88
- KeyValue :: new ( semconv:: resource:: FAAS_VERSION , "$LATEST" ) ,
89
- KeyValue :: new ( semconv:: resource:: FAAS_MAX_MEMORY , 128 * 1024 * 1024 ) ,
90
- KeyValue :: new (
91
- semconv:: resource:: AWS_LOG_GROUP_NAMES ,
92
- Value :: Array ( Array :: from ( vec ! [ StringValue :: from(
93
- "/aws/lambda/my-lambda-function" . to_string( ) ,
94
- ) ] ) ) ,
74
+ ( AWS_LAMBDA_MEMORY_LIMIT_ENV_VAR , Some ( "128" ) ) ,
75
+ (
76
+ AWS_LAMBDA_LOG_GROUP_NAME_ENV_VAR ,
77
+ Some ( "/aws/lambda/my-lambda-function" ) ,
95
78
) ,
96
- ] )
97
- . build ( ) ;
79
+ ] ,
80
+ || {
81
+ let expected = Resource :: builder_empty ( )
82
+ . with_attributes ( [
83
+ KeyValue :: new ( semconv:: resource:: CLOUD_PROVIDER , "aws" ) ,
84
+ KeyValue :: new ( semconv:: resource:: CLOUD_REGION , "eu-west-3" ) ,
85
+ KeyValue :: new (
86
+ semconv:: resource:: FAAS_INSTANCE ,
87
+ "2023/01/01/[$LATEST]5d1edb9e525d486696cf01a3503487bc" ,
88
+ ) ,
89
+ KeyValue :: new ( semconv:: resource:: FAAS_NAME , "my-lambda-function" ) ,
90
+ KeyValue :: new ( semconv:: resource:: FAAS_VERSION , "$LATEST" ) ,
91
+ KeyValue :: new ( semconv:: resource:: FAAS_MAX_MEMORY , 128 * 1024 * 1024 ) ,
92
+ KeyValue :: new (
93
+ semconv:: resource:: AWS_LOG_GROUP_NAMES ,
94
+ Value :: Array ( Array :: from ( vec ! [ StringValue :: from(
95
+ "/aws/lambda/my-lambda-function" . to_string( ) ,
96
+ ) ] ) ) ,
97
+ ) ,
98
+ ] )
99
+ . build ( ) ;
98
100
99
- let detector = LambdaResourceDetector { } ;
100
- let got = detector. detect ( ) ;
101
-
102
- assert_eq ! ( expected, got) ;
101
+ let detector = LambdaResourceDetector { } ;
102
+ let got = detector. detect ( ) ;
103
103
104
- remove_var ( AWS_LAMBDA_FUNCTION_NAME_ENV_VAR ) ;
105
- remove_var ( AWS_REGION_ENV_VAR ) ;
106
- remove_var ( AWS_LAMBDA_FUNCTION_VERSION_ENV_VAR ) ;
107
- remove_var ( AWS_LAMBDA_LOG_STREAM_NAME_ENV_VAR ) ;
108
- remove_var ( AWS_LAMBDA_MEMORY_LIMIT_ENV_VAR ) ;
109
- remove_var ( AWS_LAMBDA_LOG_GROUP_NAME_ENV_VAR ) ;
104
+ assert_eq ! ( expected, got) ;
105
+ } ,
106
+ ) ;
110
107
}
111
108
112
109
#[ sealed_test]
0 commit comments