@@ -2,40 +2,42 @@ import 'package:test/test.dart';
22import 'package:launchdarkly_common_client/src/data_sources/get_environment_id.dart' ;
33
44void main () {
5- group ('getEnvironmentId' , () {
6- test ('returns environment ID from headers' , () {
7- final headers = {'x-ld-envid' : 'test-env-123' };
8- final result = getEnvironmentId (headers);
9- expect (result, 'test-env-123' );
10- });
5+ test ('returns environment ID from headers' , () {
6+ final headers = {'x-ld-envid' : 'test-env-123' };
7+ final result = getEnvironmentId (headers);
8+ expect (result, 'test-env-123' );
9+ });
1110
12- test ('returns null when header is missing' , () {
13- final headers = < String , String > {'other-header' : 'value' };
14- final result = getEnvironmentId (headers);
15- expect (result, null );
16- });
11+ test ('returns null when header is missing' , () {
12+ final headers = < String , String > {'other-header' : 'value' };
13+ final result = getEnvironmentId (headers);
14+ expect (result, null );
15+ });
1716
18- test ('returns null when headers are null' , () {
19- final result = getEnvironmentId (null );
20- expect (result, null );
21- });
17+ test ('returns null when headers are null' , () {
18+ final result = getEnvironmentId (null );
19+ expect (result, null );
20+ });
2221
23- test ('returns null when headers are empty' , () {
24- final headers = < String , String > {};
25- final result = getEnvironmentId (headers);
26- expect (result, null );
27- });
22+ test ('returns null when headers are empty' , () {
23+ final headers = < String , String > {};
24+ final result = getEnvironmentId (headers);
25+ expect (result, null );
26+ });
2827
29- test ('handles case-sensitive header name correctly' , () {
30- final headers = {'X-LD-ENVID' : 'test-env-123' };
31- final result = getEnvironmentId (headers);
32- expect (result, null );
33- });
28+ test ('handles multiple values for environment id' , () {
29+ // Services should only send a single environment ID, but if we did get
30+ // multiple we want it to be handled safely.
31+ final headers = < String , String > {'x-ld-envid' : 'envid-a, envid-b' };
32+ final result = getEnvironmentId (headers);
33+ expect (result, 'envid-a' );
34+ });
3435
35- test ('handles environment ID with special characters' , () {
36- final headers = {'x-ld-envid' : 'env-123-abc-456' };
37- final result = getEnvironmentId (headers);
38- expect (result, 'env-123-abc-456' );
39- });
36+ test ('handles envid is empty string' , () {
37+ // Services shouldn't send an empty string, but we want to ensure it
38+ // doesn't cause any runtime issue.
39+ final headers = < String , String > {'x-ld-envid' : '' };
40+ final result = getEnvironmentId (headers);
41+ expect (result, '' );
4042 });
4143}
0 commit comments