@@ -46,21 +46,37 @@ func init() {
4646}
4747
4848const configResponseStr = `{
49- "appId": "100004458",
50- "cluster": "default",
51- "namespaceName": "application",
52- "configurations": {
53- "key1":"value1",
54- "key2":"value2"
55- },
56- "releaseKey": "20170430092936-dee2d58e74515ff3"
49+ "appId": "100004458",
50+ "cluster": "default",
51+ "namespaceName": "application",
52+ "configurations": {
53+ "key1":"value1",
54+ "key2":"value2"
55+ },
56+ "releaseKey": "20170430092936-dee2d58e74515ff3"
57+ }`
58+
59+ const grayConfigResponseStr = `{
60+ "appId": "100004458",
61+ "cluster": "default",
62+ "namespaceName": "application",
63+ "configurations": {
64+ "key1":"gray_value1",
65+ "key2":"gray_value2"
66+ },
67+ "releaseKey": "20170430092936-dee2d58e74515ff3"
5768}`
5869
5970const configFilesResponseStr = `{
6071 "key1":"value1",
6172 "key2":"value2"
6273}`
6374
75+ const grayConfigFilesResponseStr = `{
76+ "key1":"gray_value1",
77+ "key2":"gray_value2"
78+ }`
79+
6480const configAbc1ResponseStr = `{
6581 "appId": "100004458",
6682 "cluster": "default",
@@ -77,6 +93,13 @@ const tworesponseStr = `[{"namespaceName":"application","notificationId":%d},{"n
7793
7894func onlyNormalConfigResponse (rw http.ResponseWriter , req * http.Request ) {
7995 rw .WriteHeader (http .StatusOK )
96+
97+ label , ok := req .URL .Query ()["label" ]
98+ if ok && len (label ) > 0 && label [0 ] == grayLabel {
99+ fmt .Fprintf (rw , grayConfigResponseStr )
100+ return
101+ }
102+
80103 fmt .Fprintf (rw , configResponseStr )
81104}
82105
@@ -192,6 +215,23 @@ func TestApolloConfig_SyncTwoOk(t *testing.T) {
192215 Assert (t , appConfig .GetNotificationsMap ().GetNotify ("abc1" ), Equal (int64 (3 )))
193216}
194217
218+ func TestApolloConfig_GraySync (t * testing.T ) {
219+ server := initMockNotifyAndConfigServer ()
220+ appConfig := initNotifications ()
221+ appConfig .IP = server .URL
222+ appConfig .Label = grayLabel
223+ apolloConfigs := asyncApollo .Sync (func () config.AppConfig {
224+ return * appConfig
225+ })
226+ //err keep nil
227+ Assert (t , apolloConfigs , NotNilVal ())
228+ Assert (t , len (apolloConfigs ), Equal (1 ))
229+
230+ apolloConfig := apolloConfigs [0 ]
231+ Assert (t , "gray_value1" , Equal (apolloConfig .Configurations ["key1" ]))
232+ Assert (t , "gray_value2" , Equal (apolloConfig .Configurations ["key2" ]))
233+ }
234+
195235func TestApolloConfig_SyncABC1Error (t * testing.T ) {
196236 server := initMockNotifyAndConfigServerWithTwoErrResponse ()
197237 appConfig := initNotifications ()
0 commit comments