2
2
// Licensed under the MIT license.
3
3
4
4
import * as sinon from "sinon" ;
5
- import { AppConfigurationClient , AppConfigurationClientOptions , ConfigurationSetting } from "@azure/app-configuration" ;
5
+ import { AppConfigurationClient , ConfigurationSetting } from "@azure/app-configuration" ;
6
6
import { ClientSecretCredential } from "@azure/identity" ;
7
7
import { KeyVaultSecret , SecretClient } from "@azure/keyvault-secrets" ;
8
8
import * as uuid from "uuid" ;
@@ -100,22 +100,28 @@ function mockAppConfigurationClientListConfigurationSettings(...pages: Configura
100
100
} ) ;
101
101
}
102
102
103
- function mockConfigurationManagerGetClients ( isFailoverable : boolean , clientOptions ?: AppConfigurationClientOptions ) {
103
+ function mockConfigurationManagerGetClients ( isFailoverable : boolean , ... pages : ConfigurationSetting [ ] [ ] ) {
104
104
// Stub the getClients method on the class prototype
105
105
sinon . stub ( ConfigurationClientManager . prototype , "getClients" ) . callsFake ( async ( ) => {
106
106
const clients : ConfigurationClientWrapper [ ] = [ ] ;
107
107
const fakeEndpoint = createMockedEndpoint ( "fake" ) ;
108
- const fakeStaticClientWrapper = new ConfigurationClientWrapper ( fakeEndpoint , new AppConfigurationClient ( createMockedConnectionString ( fakeEndpoint ) , clientOptions ) ) ;
108
+ const fakeStaticClientWrapper = new ConfigurationClientWrapper ( fakeEndpoint , new AppConfigurationClient ( createMockedConnectionString ( fakeEndpoint ) ) ) ;
109
+ sinon . stub ( fakeStaticClientWrapper . client , "listConfigurationSettings" ) . callsFake ( ( ) => {
110
+ throw new RestError ( "Internal Server Error" , { statusCode : 500 } ) ;
111
+ } ) ;
109
112
clients . push ( fakeStaticClientWrapper ) ;
110
113
111
114
if ( ! isFailoverable ) {
112
115
return clients ;
113
116
}
114
117
115
118
const fakeReplicaEndpoint = createMockedEndpoint ( "fake-replica" ) ;
116
- const fakeDynamicClientWrapper = new ConfigurationClientWrapper ( fakeReplicaEndpoint , new AppConfigurationClient ( createMockedConnectionString ( fakeReplicaEndpoint ) , clientOptions ) ) ;
119
+ const fakeDynamicClientWrapper = new ConfigurationClientWrapper ( fakeReplicaEndpoint , new AppConfigurationClient ( createMockedConnectionString ( fakeReplicaEndpoint ) ) ) ;
117
120
clients . push ( fakeDynamicClientWrapper ) ;
118
-
121
+ sinon . stub ( fakeDynamicClientWrapper . client , "listConfigurationSettings" ) . callsFake ( ( listOptions ) => {
122
+ const kvs = _filterKVs ( pages . flat ( ) , listOptions ) ;
123
+ return getMockedIterator ( pages , kvs , listOptions ) ;
124
+ } ) ;
119
125
return clients ;
120
126
} ) ;
121
127
}
@@ -135,17 +141,6 @@ function mockAppConfigurationClientGetConfigurationSetting(kvList) {
135
141
} ) ;
136
142
}
137
143
138
- function mockAppConfigurationClientListConfigurationSettingsWithFailure ( ...pages : ConfigurationSetting [ ] [ ] ) {
139
- const stub = sinon . stub ( AppConfigurationClient . prototype , "listConfigurationSettings" ) ;
140
-
141
- // Configure the stub to throw an error on the first call and return mockedKVs on the second call
142
- stub . onFirstCall ( ) . throws ( new RestError ( "Internal Server Error" , { statusCode : 500 } ) ) ;
143
- stub . callsFake ( ( listOptions ) => {
144
- const kvs = _filterKVs ( pages . flat ( ) , listOptions ) ;
145
- return getMockedIterator ( pages , kvs , listOptions ) ;
146
- } ) ;
147
- }
148
-
149
144
// uriValueList: [["<secretUri>", "value"], ...]
150
145
function mockSecretClientGetSecret ( uriValueList : [ string , string ] [ ] ) {
151
146
const dict = new Map ( ) ;
@@ -235,7 +230,6 @@ export {
235
230
sinon ,
236
231
mockAppConfigurationClientListConfigurationSettings ,
237
232
mockAppConfigurationClientGetConfigurationSetting ,
238
- mockAppConfigurationClientListConfigurationSettingsWithFailure ,
239
233
mockConfigurationManagerGetClients ,
240
234
mockSecretClientGetSecret ,
241
235
restoreMocks ,
0 commit comments