@@ -105,16 +105,49 @@ def setUp(self):
105
105
]
106
106
)
107
107
@patch ("samtranslator.feature_toggle.feature_toggle.boto3" )
108
+ @patch ("samtranslator.feature_toggle.feature_toggle.Config" )
108
109
def test_feature_toggle_with_appconfig_provider (
109
- self , feature_name , stage , region , account_id , expected , boto3_mock
110
+ self , feature_name , stage , region , account_id , expected , config_mock , boto3_mock
110
111
):
111
112
boto3_mock .client .return_value = self .app_config_mock
113
+ config_object_mock = Mock ()
114
+ config_mock .return_value = config_object_mock
112
115
feature_toggle_config_provider = FeatureToggleAppConfigConfigProvider (
113
116
"test_app_id" , "test_env_id" , "test_conf_id"
114
117
)
115
118
feature_toggle = FeatureToggle (
116
119
feature_toggle_config_provider , stage = stage , region = region , account_id = account_id
117
120
)
121
+ boto3_mock .client .assert_called_once_with ("appconfig" , config = config_object_mock )
122
+ self .assertEqual (feature_toggle .is_enabled (feature_name ), expected )
123
+
124
+ @parameterized .expand (
125
+ [
126
+ param ("feature-1" , "beta" , "default" , "123456789123" , False ),
127
+ param ("feature-1" , "beta" , "us-west-2" , "123456789123" , True ),
128
+ param ("feature-2" , "beta" , "us-west-2" , "123456789123" , False ), # because feature is missing
129
+ param ("feature-1" , "beta" , "ap-south-1" , "123456789124" , False ), # because default is used
130
+ param ("feature-1" , "alpha" , "us-east-1" , "123456789123" , False ), # non-exist stage
131
+ param ("feature-1" , "beta" , "us-east-1" , "123456789100" , True ),
132
+ param ("feature-1" , "beta" , "us-east-1" , "123456789123" , False ),
133
+ # any None for stage, region and account_id returns False
134
+ param ("feature-1" , None , None , None , False ),
135
+ param ("feature-1" , "beta" , None , None , False ),
136
+ param ("feature-1" , "beta" , "us-west-2" , None , False ),
137
+ param ("feature-1" , "beta" , None , "123456789123" , False ),
138
+ ]
139
+ )
140
+ @patch ("samtranslator.feature_toggle.feature_toggle.boto3" )
141
+ def test_feature_toggle_with_appconfig_provider_and_app_config_client (
142
+ self , feature_name , stage , region , account_id , expected , boto3_mock
143
+ ):
144
+ feature_toggle_config_provider = FeatureToggleAppConfigConfigProvider (
145
+ "test_app_id" , "test_env_id" , "test_conf_id" , self .app_config_mock
146
+ )
147
+ feature_toggle = FeatureToggle (
148
+ feature_toggle_config_provider , stage = stage , region = region , account_id = account_id
149
+ )
150
+ boto3_mock .client .assert_not_called ()
118
151
self .assertEqual (feature_toggle .is_enabled (feature_name ), expected )
119
152
120
153
0 commit comments