---
cases:
  - note: example/both
    query: data.opa.example = x
    modules:
      - |
        package opa.example

        public_servers contains server if {
        	server = data.servers[_]
        	server.ports[_] = data.ports[i].id
        	data.ports[i].networks[_] = data.networks[j].id
        	data.networks[j].public = true
        }

        violations contains server if {
        	server = data.servers[_]
        	server.protocols[_] = "http"
        	data.opa.example.public_servers[server]
        }
      - |
        package topdown_test_partial

        __result__ := _result if {
        	_result = {{"id": "s4", "name": "dev", "ports": ["p1", "p2"], "protocols": ["http"]}}
        }
    data:
      networks:
        - id: n1
          public: false
        - id: n2
          public: false
        - id: n3
          public: true
      ports:
        - id: p1
          networks:
            - n1
        - id: p2
          networks:
            - n3
        - id: p3
          networks:
            - n2
      servers:
        - id: s1
          name: app
          ports:
            - p1
            - p2
            - p3
          protocols:
            - https
            - ssh
        - id: s2
          name: db
          ports:
            - p3
          protocols:
            - mysql
        - id: s3
          name: cache
          ports:
            - p3
          protocols:
            - memcache
            - http
        - id: s4
          name: dev
          ports:
            - p1
            - p2
          protocols:
            - http
    input_term: "{}"
    want_result:
      - x:
          public_servers:
            - id: s1
              name: app
              ports:
                - p1
                - p2
                - p3
              protocols:
                - https
                - ssh
            - id: s4
              name: dev
              ports:
                - p1
                - p2
              protocols:
                - http
          violations:
            - id: s4
              name: dev
              ports:
                - p1
                - p2
              protocols:
                - http
