Open tw-pmcfadden opened 5 years ago
Hi @tw-pmcfadden .
For example, how do you want to write a test for awspec ? Could you show me a pseudocode ?
Assuming a nonprod and prod account (with prod hosting example.com). And assuming that we've already loaded credentials for nonprod
it 'should having matching ns records in nonprod and prod' do
nonprod_nameservers = route53_hosted_zone('nonprod.example.com.').find_nameservers
Awsecrets.with_credentials(read_prod_credentials) do
expect(route53_hosted_zone('example.com.').record_set('nonprod.example.com').find_nameservers).to match_array(nonprod_nameservers)
end
end
I'm open to other thoughts on this as well of course.
Awsecrets.load
set config to Aws.config
.
Aws.config
is class property.
🤔
it 'should having matching ns records in nonprod and prod' do
nonprod_nameservers = route53_hosted_zone('nonprod.example.com.').find_nameservers
Awsecrets.load(read_prod_credentials)
expect(route53_hosted_zone('example.com.').record_set('nonprod.example.com').find_nameservers).to match_array(nonprod_nameservers)
Awsecrets.load(read_nonprod_credentials)
end
Yea that's fair. I was worried about the state of Awsecrets.config depending on if the test failed or not. But maybe moving the Awsecrets.load(read_nonprod_credentials)
into an after(:each) will handle that for me.
Thanks for taking a look at it. Keep up the good work!
We're using awspec to test our resources and one of the things we're testing is dns delegation between accounts. In TF you just create an additional aws provider and give it a different profile/credentials. Then specify that for a given resource. However testing that is difficult. I was thinking if we could either do an Awsecrets.load and give it a block (the given test/block of tests) It would use different credentials for that.
Our current workaround is to have 2 separate spec files and reset the ~/.aws credentials between those two. Maybe a better option is a setup/teardown for a test loading different yamls?