import json

from kat.harness import Query

from abstract_tests import AmbassadorTest, ServiceType, EGRPC

class AcceptanceGrpcBridgeTest(AmbassadorTest):

    target: ServiceType

    def init(self):
        self.target = EGRPC()

    def config(self):
        yield self, self.format("""
---
apiVersion: ambassador/v0
kind:  Module
name:  ambassador
config:
    enable_grpc_http11_bridge: True
""")

        yield self, self.format("""
---
apiVersion: ambassador/v0
kind:  Mapping
grpc: True
prefix: /echo.EchoService/
rewrite: /echo.EchoService/
name:  {self.target.path.k8s}
service: {self.target.path.k8s}
""")

    def queries(self):
        # [0]
        yield Query(self.url("echo.EchoService/Echo"), headers={ "content-type": "application/grpc", 
                                                                    "requested-status": "0" }, expected=200)

         # [1]
        yield Query(self.url("echo.EchoService/Echo"),  headers={ "content-type": "application/grpc", 
                                                                    "requested-status": "7" }, expected=200)

    def check(self):
        # [0]
        assert self.results[0].status == 200
        assert self.results[0].headers["Grpc-Status"] == ["0"]

        # [0]
        assert self.results[1].status == 200
        assert self.results[1].headers["Grpc-Status"] == ["7"]

@@ -1,17 +1,4 @@
-import json%0A%0A
 from
@@ -688,16 +688,36 @@
 /Echo%22),
+%0A                   
  headers
@@ -759,77 +759,8 @@
 c%22, 
-%0A                                                                    
 %22req
@@ -777,24 +777,44 @@
 tus%22: %220%22 %7D,
+%0A                   
  expected=20
@@ -817,17 +817,16 @@
 d=200)%0A%0A
- 
         
@@ -885,16 +885,35 @@
 /Echo%22),
+%0A                  
   header
@@ -956,77 +956,8 @@
 c%22, 
-%0A                                                                    
 %22req
@@ -978,16 +978,36 @@
 : %227%22 %7D,
+%0A                   
  expecte
@@ -1053,53 +1053,8 @@
 %5B0%5D%0A
-        assert self.results%5B0%5D.status == 200%0A
     
@@ -1128,55 +1128,10 @@
  # %5B
-0%5D%0A        assert self.results%5B1%5D.status == 200
+1%5D
 %0A   

Clean up existing gRPC bridge test (make it like t_tcpmapping.py)