Code Monkey home page Code Monkey logo

Comments (11)

cdhunt avatar cdhunt commented on May 24, 2024

That's a great idea.

from poshspec.

DexterPOSH avatar DexterPOSH commented on May 24, 2024

@cdhunt I have that already working in my local repo (minor changes).
Should I create a PR ?

from poshspec.

cdhunt avatar cdhunt commented on May 24, 2024

@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.

DexterPOSH avatar DexterPOSH commented on May 24, 2024

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.

DexterPOSH avatar DexterPOSH commented on May 24, 2024

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.

cdhunt avatar cdhunt commented on May 24, 2024

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.

DexterPOSH avatar DexterPOSH commented on May 24, 2024

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.

asipe avatar asipe commented on May 24, 2024

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.

DexterPOSH avatar DexterPOSH commented on May 24, 2024

@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.

cdhunt avatar cdhunt commented on May 24, 2024

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.

DexterPOSH avatar DexterPOSH commented on May 24, 2024

@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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.