Hi, I am trying to implement request/response prot...
# protobufs
s
Hi, I am trying to implement request/response proto matcher in golang for something similar mentioned below
Copy code
message Request {
  string id = 1;
  map<string, string> device_headers = 2;
  map<string, string> params = 3;
  repeated break_duration_ms = 4; 
}
In my use case objects and arrays can be empty as well. I am not able to find some good resources/examples for the same in golang. cc: @Praful Poudel
m
What have you tried Saif?
s
until now i have used these proto matching
Copy code
grpcInteraction := `{
		"pact:proto": "` + filepath.ToSlash(dir) + `",
		"pact:proto-service": "Calculate/Rectangle",
		"pact:content-type": "application/protobuf",
		"pact:protobuf-config": {
			"additionalIncludes": ["` + filepath.ToSlash(additionalDir) + `", "` + filepath.ToSlash(additionalDir2) + `"]
	  	},
		"request": {
			"id": "matching(type, '1')",
			"correlation_id": "matching(type, 'sdfsadghhhhhh')",
			"params": {},
			"protocol": "matching(type, 'dash')",
			"request_ctx": {
				"tenant_id": "matching(type, 'beam')",
				"client_ip": "matching(semver, '198.147.1.9')",
				"user_agent": "matching(type, 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/122.0.0.0 Safari/537.36')",
				"pre_play_req_timestamp": "matching(datetime, 'yyyy-MM-ddTHH:mm:ss.sssssssssZ', '2024-03-18T16:24:16.977359576Z')",
				"mode": "matching(type, 'MODE_XYZ')",
				"asset_id": "matching(type,'')"
			},
			"playlist_duration": "Like('2564s')",
			"timeout": "Like('4s')",
			"timestamp": "Like('2024-03-18T16:24:17.003265Z')"
      },
      ...
}`
but i am not sure how can i do the matching for something below object
Copy code
"breaks": [
        {
            "id": "pre.1460231218",
            "break_id": "2341234-86f4-4955-8275-db76531ce378.0",
            "trackers": [
                {
                    "event": "breakEnd",
                    "url": "<http://ggooel.com|ggooel.com>"
                },
                ...
            ]
        },
        {
            "id": "cue_point--1843487036",
            "break_id": "cd1cefc0-86f4-4955-8275-db76531ce378.1",
            "duration_ms": 90089,
            "time_offset": 396000,
            "break_index": 1,
            "trackers": [
                {
                    "event": "breakStart",
                    "url": "<https://yahoo.com>"
                },
               ...
            ],
            "test_details": [
                {
                    "id": "314234-4360-11ee-971a-e6a552723314",
                    "duration_ms": 30030,
                    "creative_id": "48637382",
                    "manifest_creative_url": "c7d42618-3214-1432-a278-ac3d3a420054/0_32301f.mpd",
                    "xyz": {
                        "id": "3214324",
                        "title": "Placement 3",
                        "duration_ms": "30030",
                        "trackers": [
                            {
                                "event": "midpoint",
                                "url": "<http://test1.com|test1.com>"
                            },
                           ...
                        ],
                        "extensions": [
                            "[{\"type\":\"Test\",\"creativeParameters\":[{\"creativeId\":\"48123137382\",\"name\":\"test_reporting\",\"type\":\"Linear\",\"value\":\"advertiser_name:Test active advertiser;advertiser_id:1138148;1660676279606087178\"}]}]"
                        ],
                        "xyz_verifications": "[]",
                        "creative_type": "CREATIVE_TYPE",
                        "xyz_metadata": {
                            "xyz_id": "65182639",
                            "xyz_system": "ERWLJ"
                        },
                        "xyzpaid": {},
                        "error": [
                            "<http://test4.com|test4.com>"
                        ],
                        "xyz_ad_id": "413243242639.140527165835520"
                    },
                    "xyz_creative_id": "x/y/z.mp4",
                    "xyz_creative_uuid": "c7d42618-6558-512d-a278-ac3d3a420054",
                    "xyz_encode": {
                        "uri": "c7d42618-6558-512d-a278-ac3d3a420054/0_32301f.mpd",
                        "origin_id": "s1:avc-afs-media-us-east-1-dev"
                    }
                },
                ...
            ]
        }
    ],
as you will notice few of the keys is not present in further loop iteration
m
In contract testing, you wouldn’t test all of these combinations in one test. For each expected object type, you should have a separate test. (howtooptional)
m
See more on ☝️
I’d suggest testing a version where all of the fields are there and a combination where the least are there. If there are other polymorphisms that matter, add those scenarios in too
s
Thanks, will check the doc.
👍 1