File tree Expand file tree Collapse file tree 2 files changed +27
-2
lines changed Expand file tree Collapse file tree 2 files changed +27
-2
lines changed Original file line number Diff line number Diff line change 1313from .config import config
1414
1515NAME_PATTERN = r"^[^\-\.][\w\-\.]+$"
16- ENV_VARS_PATTERN = r"^([\w:.\/]+=[\w:.\/]+)(,[\w:.\/]+=[\w:.\/]+)*$"
16+ ENV_VARS_PATTERN = r"^([\w:.\/\- ]+=[\w:.\/\- ]+)(,[\w:.\/\- ]+=[\w:.\/\- ]+)*$"
1717ENVIRONMENT_ENVVAR_NAME = "CFC_ENVIRONMENT"
1818
1919env_app = typer .Typer ()
@@ -35,7 +35,7 @@ def tag_callback(name: str) -> str:
3535 return name_callback (name )
3636
3737
38- def env_var_callback (env_vars : str ) -> dict :
38+ def env_var_callback (env_vars : str ) -> str :
3939 if not env_vars :
4040 return env_vars
4141 if not re .fullmatch (ENV_VARS_PATTERN , env_vars ):
Original file line number Diff line number Diff line change 1+ from unittest import TestCase
2+
3+ import typer
4+
5+ from cfc .environment import env_var_callback
6+
7+
8+ class TestEnvironment (TestCase ):
9+ def test_env_var_callback (self ):
10+ # Test valid input
11+ env_var_callback ("VAR1=VALUE1,VAR2=VALUE2" )
12+ env_var_callback ("VAR1=abc-123:as123" )
13+ env_var_callback ("VAR1=abc-123:as123,VAR2=abc-123:as123" )
14+ env_var_callback ("VAR1=https://example.com,VAR2=abc-123:as123" )
15+
16+ # test empty input
17+ env_var_callback ("" )
18+
19+ # test invalid input
20+ with self .assertRaises (typer .BadParameter ):
21+ env_var_callback ("VAR1=VALUE1,VAR2=VALUE2," )
22+ with self .assertRaises (typer .BadParameter ):
23+ env_var_callback ("VAR1=VALUE1,VAR2=VALUE2,VAR3" )
24+ with self .assertRaises (typer .BadParameter ):
25+ env_var_callback ("VAR1=VALUE1,VAR2=VALUE2,VAR3=VALUE3=" )
You can’t perform that action at this time.
0 commit comments