Skip to content

xDnsRecordMx: Unit test missing Mock #204

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Sudman1 opened this issue Mar 15, 2021 · 2 comments · Fixed by #234
Closed

xDnsRecordMx: Unit test missing Mock #204

Sudman1 opened this issue Mar 15, 2021 · 2 comments · Fixed by #234
Labels
good first issue The issue should be easier to fix and can be taken up by a beginner to learn to contribute on GitHub tests The issue or pull request is about tests only.

Comments

@Sudman1
Copy link
Contributor

Sudman1 commented Mar 15, 2021

Details of the scenario you tried and the problem that is occurring

Cannot throw Get-DnsServerResourceRecord Stub call, as it seems one of the MSFT_xDnsRecordMx\Set-TargetResource tests may not have mocked it.

Verbose logs showing the problem

...
  Describing MSFT_xDnsRecordMx\Set-TargetResource

    Context When managing MX type DNS record
      [-] Calls Add-DnsServerResourceRecord in the set method when Ensure is Present 98ms
        RuntimeException: Get-DnsServerResourceRecord: StubNotImplemented
        at Get-DnsServerResourceRecord, C:\Users\james\Documents\code\xDnsServer\tests\Unit\Stubs\DnsServer.psm1: line 5662
        at Set-TargetResource, C:\Users\james\Documents\code\xDnsServer\output\xDnsServer\0.0.1\DSCResources\MSFT_xDnsRecordMx\MSFT_xDnsRecordMx.psm1: line 163
        at <ScriptBlock>, C:\Users\james\Documents\code\xDnsServer\tests\Unit\MSFT_xDnsRecordMx.Tests.ps1: line 156
VERBOSE: Updating DNS record 'MX' for target 'mail.contoso.com.' in zone 'contoso.com' on 'localhost'.
...

Suggested solution to the issue

Verify that a mock for Get-DnsServerResourceRecord exists within the scope of the test (prior to being called) at line 156

@johlju johlju added good first issue The issue should be easier to fix and can be taken up by a beginner to learn to contribute on GitHub help wanted The issue is up for grabs for anyone in the community. tests The issue or pull request is about tests only. labels Mar 15, 2021
@johlju
Copy link
Member

johlju commented Mar 15, 2021

The content of the stub should be changed from (which shows the missing mock as above)

Write-Verbose ('{0}: StubNotImplemented' -f $MyInvocation.MyCommand)

to

throw ('{0}: StubNotImplemented' -f $MyInvocation.MyCommand)

@johlju
Copy link
Member

johlju commented Mar 26, 2021

The resource have been deprecated and the unit test has been remove so we can add the throw back in the stub.

johlju added a commit that referenced this issue Mar 26, 2021
- DnsServerDsc
  - Fix stub `Get-DnsServerResourceRecord` so it throws if it is not mocked
    correctly (issue #204).
@johlju johlju removed the help wanted The issue is up for grabs for anyone in the community. label Mar 26, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue The issue should be easier to fix and can be taken up by a beginner to learn to contribute on GitHub tests The issue or pull request is about tests only.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants