You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
feat: Support setting serverId with SERVERPOD_SERVER_ID env var (serverpod#3238)
Added the ability to set the serverId from environment variables (SERVER_ID) in addition to the command line argument
(--server-id). If both options are provided, the command line argument takes precedence.
Closes [serverpod#2832](serverpod#2832)
Copy file name to clipboardExpand all lines: packages/serverpod_shared/test/config_test.dart
+115
Original file line number
Diff line number
Diff line change
@@ -978,4 +978,119 @@ redis:
978
978
979
979
expect(config.redis?.enabled, isTrue);
980
980
});
981
+
982
+
test(
983
+
'Given a Serverpod config with server id when loading from Map then serverId configuration matches supplied value.',
984
+
() {
985
+
var serverpodConfig ='''
986
+
apiServer:
987
+
port: 8080
988
+
publicHost: localhost
989
+
publicPort: 8080
990
+
publicScheme: http
991
+
serverId: testServer1
992
+
''';
993
+
994
+
var config =ServerpodConfig.loadFromMap(
995
+
runMode,
996
+
serverId,
997
+
passwords,
998
+
loadYaml(serverpodConfig),
999
+
);
1000
+
1001
+
expect(config.serverId, 'testServer1');
1002
+
});
1003
+
1004
+
test(
1005
+
'Given a Serverpod config with only the api server configuration but the environment variables containing the server id when loading from Map then the server id matches supplied value.',
1006
+
() {
1007
+
var config =ServerpodConfig.loadFromMap(
1008
+
runMode,
1009
+
serverId,
1010
+
passwords,
1011
+
{
1012
+
'apiServer': {
1013
+
'port':8080,
1014
+
'publicHost':'localhost',
1015
+
'publicPort':8080,
1016
+
'publicScheme':'http',
1017
+
},
1018
+
},
1019
+
environment: {
1020
+
'SERVERPOD_SERVER_ID':'testServer1',
1021
+
},
1022
+
);
1023
+
1024
+
expect(config.serverId, 'testServer1');
1025
+
});
1026
+
1027
+
test(
1028
+
'Given a Serverpod config with only the api server configuration but the server id given as an argument then the server id matches supplied value.',
1029
+
() {
1030
+
var config =ServerpodConfig.loadFromMap(
1031
+
runMode,
1032
+
'testServer1',
1033
+
passwords,
1034
+
{
1035
+
'apiServer': {
1036
+
'port':8080,
1037
+
'publicHost':'localhost',
1038
+
'publicPort':8080,
1039
+
'publicScheme':'http',
1040
+
},
1041
+
},
1042
+
);
1043
+
1044
+
expect(config.serverId, 'testServer1');
1045
+
});
1046
+
1047
+
test(
1048
+
'Given a Serverpod config with server id when loading from Map and the environment variables containing the server id but the server id given as an argument is the default value then the server id from environment takes the precedence.',
1049
+
() {
1050
+
var serverpodConfig ='''
1051
+
apiServer:
1052
+
port: 8080
1053
+
publicHost: localhost
1054
+
publicPort: 8080
1055
+
publicScheme: http
1056
+
serverId: testServerIdFromConfig
1057
+
''';
1058
+
1059
+
var config =ServerpodConfig.loadFromMap(
1060
+
runMode,
1061
+
serverId,
1062
+
passwords,
1063
+
loadYaml(serverpodConfig),
1064
+
environment: {
1065
+
'SERVERPOD_SERVER_ID':'testServerIdFromEnv',
1066
+
},
1067
+
);
1068
+
1069
+
expect(config.serverId, 'testServerIdFromEnv');
1070
+
});
1071
+
1072
+
test(
1073
+
'Given a Serverpod config with server id when loading from Map and the environment variables containing the server id and the server id given as an argument is a custom defined value then the server id from the argument takes the precedence.',
0 commit comments