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

ast+topdown+planner: non-built-in function mocking #4616

Commits on Apr 28, 2022

  1. ast+topdown+planner: replacement of non-built-in functions via 'with'

    Follow-up to open-policy-agent#4540
    
    We can now mock functions that are user-defined:
    
        package test
    
        f(_) = 1 {
            input.x = "x"
        }
        p = y {
            y := f(1) with f as 2
        }
    
    ...following the same scoping rules as laid out for built-in mocks.
    The replacement can be a value (replacing all calls), or a built-in,
    or another non-built-in function.
    
    Also addresses bugs in the previous slice:
    * topdown/evalCall: account for empty rules result from indexer
    * topdown/eval: capture value replacement in PE could panic
    
    Note: in PE, we now drop 'with' for function mocks of any kind:
    
    These are always fully replaced in the saved support modules, so
    this should be OK.
    
    When keeping them, we'd also have to either copy the existing definitions
    into the support module; or create a function stub in it.
    
    Fixes open-policy-agent#4449.
    
    Signed-off-by: Stephan Renatus <stephan.renatus@gmail.com>
    srenatus committed Apr 28, 2022
    Copy the full SHA
    1dc2f27 View commit details
    Browse the repository at this point in the history