Comments (11)
That's a great idea.
from poshspec.
@cdhunt I have that already working in my local repo (minor changes).
Should I create a PR ?
from poshspec.
@DexterPOSH I really prefer to not implement test specific parameters like Type
. I think I would prefer to just create separate functions like DnsARecord
and DnsMxRecord
. By using just the Property
and Qualifier
parameters, the test names remain consistent and meaningful without discarding the work done by Get-PoshspecParam
. Does that make sense?
from poshspec.
But this would bring a lot of extra work. For Example there are a lot of DNS query types, I have something like below in the validateset for the Type
# Type of the Name query
[Parameter()]
[ValidateSet('A_AAAA','A','AAAA','NS','MX','MD','MF','CNAME','SOA',
'MB','MG','MR','NULL','WKS','PTR','HINFO','MINFO','TXT','RP','AFSDB',
'X25','ISDN','RT','SRV','DNAME','OPT','DS','RRSIG','NSEC','DNSKEY',
'DHCID','NSEC3','NSEC3PARAM','ANY','ALL')]
[String]$Type
So one would need to create those many separate DNSRecord functions, hope you get my point.
from poshspec.
I understand trying to have consistent parameters for all the Functions being added.
Since these arguments are actually being passed to the underlying cmdlet, Can't there be a generic parameter like ArgumentList (Accepts hashtable) here ?
Purpose of it would be to simply append the key-value pairs to the underlying cmdlet expression , Make sense ?
from poshspec.
Each Dns record will likely have different testing logic. You don't necessarily need to implement a function for all types. Just work on what helps you. However, as an example, testing a CNAME you might want to test the NameHost property or the IP4Address of the resolved A record. By sticking all of that logic into one function, you will end up with a bunch of tests with very similar Names and it will be more difficult to discern from the results what was tested.
You can also create you own hash with Expression and Name keys to pass to Invoke-PoshspecExpression
or you can manually construct It
statement without using the helpers.
How you are designing the function doesn't fit into the pattern of Poshspec. It's perfectly valid from a standalone function standpoint, but I would like each function in Poshspec to be consistent and simple so users do not have to look up detailed Help for every type of test they want to use.
I would like to open it up for discussion with others If you want to submit the PR as you have it.
from poshspec.
hmmm....having read your response, I understand that adding test specific params would open a can of worms.
For the time being writing the IT blocks for my own specific use case makes more sense
I will re-work on creating separate DNSARecord and DNSMXRecord functions now.
from poshspec.
I was faced with a similar problem when I read this thread.
My particular issue is that I need to get some additional headers passed to the Http function. I was going to implement this as an additional optional parameter. After reading this thread it doesn't sound like that is the way to go. Any thoughts on how something like this might be better implemented?
from poshspec.
@asipe I ended up doing few changes in PoshSpec (ugly ones) 😝
Which lets you do something like this
DNSHost @{Name='cloud.local';Server='10.116.2.250'} { Should NOT Be $null }
This simply splats the target hash to the Resolve-DNSName but it works for me at the moment.
So you can pass any additional parameters to the underlying function, but this meant I had to update every public function for that (remember I said ugly).
from poshspec.
Taking a hashtable of additional Cmdlet parameters is a pretty good generic solution. That aligns with how MS does the Requires -Module
syntax.
from poshspec.
@cdhunt I have sort of incomplete implementation of the above working in my branch.
To summarize had to modify the Target parameter to take an Object type and then make decisions based on whether it is a string or hashtable. If a hashtable is passed as a target, then it is splatted to the underlying cmdlet in the expression.
For Example
Describe 'CIMObjects' {
CimObject Win32_OperatingSystem SystemDirectory { Should Be C:\WINDOWS\system32 }
CimObject @{ClassName='Win32_service';Filter="Name='WinRm'"} Status {Should be 'Ok'}
}
Describe 'DNSHost' {
DnsHost Google.com {Should not be $null}
DnsHost @{name='Google.com';Type='A'} {Should not be $null}
}
Let me know your thoughts on the implementation. Branch is here
P.S. - I have only added this ability to few of the underlying Public types at the moment.
from poshspec.
Related Issues (20)
- Unable to call Custom functions in poshspec.
- Http tests don't work against https URLs with invalid certs HOT 4
- Additional Test: AuditPolicy
- Additional Test: LocalUser
- Additional Test: UserRightsAssignment
- Additional Private Function: Test-RunAsAdmin
- Service Function: Get-Service vs Get-WmiObject\Get-CimInstance HOT 1
- Pester 4.x support - Allow for new syntax HOT 2
- Documentation Transition HOT 3
- CHANGELOG HOT 1
- Poshspec Pester Tests broken from PR #44 HOT 1
- more efficient method for package checking HOT 1
- Path prompt with SoftwareProduct HOT 9
- How to use "File Should Contain" rule HOT 4
- PowerShell Gallery shows Pester functions in this module HOT 1
- Update Wiki HOT 2
- Unable to test PowerShell Auditing Settings via registry HOT 2
- Cannot bind argument to parameter 'Command' because it is null. HOT 1
- Compatibility with latest versions of pester
- Issues
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from poshspec.