Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

rego_type_error: undefined function

I am new to OPA and rego files. I have created a rego file like this :

package sample.access
import data.myaccess

default allow = false
allow = true {
    myaccess.is_user_allowed(input.user)
}

And, I have created test rego file like this :

package sample.access

test_allow_positive{
    allow with input as {
        "user": "user1"
    } with data.myaccess as {
        {
            {"user": "user1"},
            {"user": "user2"}
        }
            
    }
}

When I run this test case, I am getting error like "rego_type_error: undefined function data.myaccess.is_user_allowed". Help me to fix this. Thanks

like image 912
sharmila Avatar asked Jun 13 '26 03:06

sharmila


1 Answers

I was facing a similar issue, probably the below solution might help.

I had a function make_err, in the file myutils.rego which I was using in myModule-test.rego file.

When I ran the command like this:

user@ubuntu:~/rules$./opa test myModule-test.rego

Got this error:

1 error occurred: myModule-test.rego:7: rego_type_error: undefined function data.myutils.make_err

When I gave the below command, it worked:

user@ubuntu:~/rules$ ./opa test myutils.rego myModule-test.rego
PASS: 11/11

It seems we need to load all the modules on which the current test depends.

like image 183
NPE Avatar answered Jun 17 '26 16:06

NPE