aws-sdk-client-mock icon indicating copy to clipboard operation
aws-sdk-client-mock copied to clipboard

Multiple instantiations of class on same mock

Open justin-masse opened this issue 6 months ago • 0 comments

Hello,

I have a lambda that loops through 7-8 AWS accounts and assumes a role in each and then runs ListSecretsCommand using aws secretsmanager with SDKv3.

However, I am unable to efficiently set up the mock for ListSecretsCommand due to the fact that I do not pass it anything during instantiation. So I'm only able to set up my mock like:

for(const env of myEnvs) {
        secretsClientMock.on(ListSecretsCommand).resolves({
            SecretList: myAccountsSecretList.map(secretName => { 
                return { Name: `${env}${secretName}` }
            })
        })
    }

However, this loop causes it to only resolve the LAST value passed into the resolves(). It will not set up a watcher for EACH item in the loop? Is there a way around this? I do not know the exact ordering of myEnvs at all times (yes I could sort them but updating the code for a test is /vomit).

Ideally I could set a bunch of mock resolves and it wouldn't matter what order it would just match them 1:1 as they appear

justin-masse avatar Jul 30 '24 18:07 justin-masse