Skip to content
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

Improve PropertyQueryTaskWriter writer matches capabilities #6

Open
Larusso opened this issue Oct 28, 2021 · 1 comment
Open

Improve PropertyQueryTaskWriter writer matches capabilities #6

Larusso opened this issue Oct 28, 2021 · 1 comment

Comments

@Larusso
Copy link
Member

Larusso commented Oct 28, 2021

##Description
The PropertyQueryTaskWriter class contains a matches method which internally checks the result stdout for a given string

result.standardOutput.contains("${path}${separator}${value}")

This works fine in 90% of our usecases. I would be nice if we could extend this to pass more flexible matcher objects.

See the following usecase

when:
        def query = new PropertyQueryTaskWriter("${extensionName}.${property}", pInvocation.toString())
        query.write(buildFile)
        def result = runTasksSuccessfully(query.taskName)

        then:
        query.matches(result, testValue)

        where:
        property         | method                  | rawValue         | expectedValue                        | type                       | location                     | propertyInvocation
        "secretsKey"     | _                       | _                | "a generated SecretKeySpec"          | _                          | PropertyLocation.none        | ".map({'${expectedValue}'}).getOrNull()"
        "secretsKey"     | _                       | "18273645".bytes | _                                    | "SecretKeySpecFilePathRaw" | PropertyLocation.environment | ".map({it.getEncoded()}).getOrNull()"
        "secretsKey"     | _                       | "81726354".bytes | _                                    | "SecretKeySpecFilePathRaw" | PropertyLocation.property    | ".map({it.getEncoded()}).getOrNull()"
        "secretsKey"     | toSetter(property)      | "12348765".bytes | _                                    | "SecretKeySpecFile"        | PropertyLocation.script      | ".map({it.getEncoded()}).getOrNull()"
        "secretsKey"     | toProviderSet(property) | "87654321".bytes | _                                    | "Provider<SecretKeySpec>"  | PropertyLocation.script      | ".map({it.getEncoded()}).getOrNull()"
        "secretsKey"     | toProviderSet(property) | "12345678".bytes | _                                    | "SecretKeySpec"            | PropertyLocation.script      | ".map({it.getEncoded()}).getOrNull()"
        "secretResolver" | _                       | _                | new SecretResolverChain().toString() | _                          | PropertyLocation.none        | _

        value = (type != _) ? wrapValueBasedOnType(rawValue, type.toString(), wrapValueFallback) : rawValue
        pInvocation = (propertyInvocation != _) ? propertyInvocation : ".getOrNull().toString()"
        providedValue = (location == PropertyLocation.script) ? type : value
        testValue = (expectedValue == _) ? rawValue : expectedValue
        reason = location.reason() + ((location == PropertyLocation.none) ? "" : "  with '$providedValue' ")
        escapedValue = (value instanceof String) ? escapedPath(value) : value
        invocation = (method != _) ? "${method}(${escapedValue})" : "${property} = ${escapedValue}"

In the first instance of the test table I need to check if the value returned is not null. I actually don't care about the actual value printed by the property query writer. I help myself by adjusting the invocation to trick the system into printing a static string value ("a generated SecretKeySpec") or null. This should be better addressable because this trick needs a lot of head gymnastic to understand.

The second issue lies in the fact that we only print values and compare them. For some types which have no good toString implementation we can work with this yields also a challenge. In the example above I also used the trick to map the actual result into printing a different value. The rawValue here is also the initial value I use in a custom wrapValueFallback impl. This again works but needs a high level of understanding by the reader.

So it would be nice if we could address this and implement some more features in the query writer to support:

  • different match statements or a higher level concept to express
    • equals
    • contains
    • regex
    • isTrue/isFalse
    • isNull/isNotNull
    • etc
  • a clean way to describe how objects are compared to each other.
@Azurelol
Copy link
Collaborator

Merged a PR which added a few of these recently:

  • equals
  • contains
  • isTrue/isFalse
  • isNull/isNotNull

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants