go.temporal.io/server@v1.23.0/common/testing/protoassert/assert_test.go (about) 1 // The MIT License 2 // 3 // Copyright (c) 2020 Temporal Technologies Inc. All rights reserved. 4 // 5 // Copyright (c) 2020 Uber Technologies, Inc. 6 // 7 // Permission is hereby granted, free of charge, to any person obtaining a copy 8 // of this software and associated documentation files (the "Software"), to deal 9 // in the Software without restriction, including without limitation the rights 10 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 // copies of the Software, and to permit persons to whom the Software is 12 // furnished to do so, subject to the following conditions: 13 // 14 // The above copyright notice and this permission notice shall be included in 15 // all copies or substantial portions of the Software. 16 // 17 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23 // THE SOFTWARE. 24 25 package protoassert_test 26 27 import ( 28 "testing" 29 30 commonpb "go.temporal.io/api/common/v1" 31 workflowpb "go.temporal.io/api/workflow/v1" 32 "go.temporal.io/server/common/testing/protoassert" 33 ) 34 35 const myUUID = "deb7b204-b384-4fde-85c6-e5a56c42336a" 36 37 type noProtoNoCry struct { 38 A float64 39 B string 40 C []bool 41 } 42 43 type canHazProto struct { 44 A float64 45 B *commonpb.WorkflowExecution 46 } 47 48 func TestProtoElementsMatch(t *testing.T) { 49 assert := protoassert.New(t) 50 for _, tc := range []struct { 51 Name string 52 A any 53 B any 54 }{{ 55 Name: "Shallow proto object - in order", 56 A: []*commonpb.WorkflowExecution{{ 57 WorkflowId: "some random workflow ID", 58 RunId: myUUID, 59 }, { 60 WorkflowId: "second workflow", 61 RunId: myUUID, 62 }}, 63 B: []*commonpb.WorkflowExecution{{ 64 WorkflowId: "some random workflow ID", 65 RunId: myUUID, 66 }, { 67 WorkflowId: "second workflow", 68 RunId: myUUID, 69 }}, 70 }, { 71 Name: "Shallow proto object - out of order", 72 A: []*commonpb.WorkflowExecution{{ 73 WorkflowId: "some random workflow ID", 74 RunId: myUUID, 75 }, { 76 WorkflowId: "second workflow", 77 RunId: myUUID, 78 }}, 79 B: []*commonpb.WorkflowExecution{{ 80 WorkflowId: "second workflow", 81 RunId: myUUID, 82 }, { 83 WorkflowId: "some random workflow ID", 84 RunId: myUUID, 85 }}, 86 }, { 87 Name: "Structs containing proto", 88 A: []canHazProto{{ 89 A: 13, 90 B: &commonpb.WorkflowExecution{ 91 WorkflowId: "some random workflow ID", 92 RunId: myUUID, 93 }, 94 }, { 95 A: 12, 96 B: &commonpb.WorkflowExecution{ 97 WorkflowId: "second random workflow ID", 98 RunId: myUUID, 99 }, 100 }}, 101 B: []canHazProto{{ 102 A: 12, 103 B: &commonpb.WorkflowExecution{ 104 WorkflowId: "second random workflow ID", 105 RunId: myUUID, 106 }, 107 }, { 108 A: 13, 109 B: &commonpb.WorkflowExecution{ 110 WorkflowId: "some random workflow ID", 111 RunId: myUUID, 112 }, 113 }}, 114 }, { 115 Name: "Nested proto struct", 116 A: []*workflowpb.WorkflowExecutionInfo{ 117 { 118 Execution: &commonpb.WorkflowExecution{ 119 WorkflowId: "some random workflow ID", 120 RunId: myUUID, 121 }, 122 }, { 123 Execution: &commonpb.WorkflowExecution{ 124 WorkflowId: "second random workflow ID", 125 RunId: myUUID, 126 }, 127 }}, 128 B: []*workflowpb.WorkflowExecutionInfo{ 129 { 130 Execution: &commonpb.WorkflowExecution{ 131 WorkflowId: "second random workflow ID", 132 RunId: myUUID, 133 }, 134 }, { 135 Execution: &commonpb.WorkflowExecution{ 136 WorkflowId: "some random workflow ID", 137 RunId: myUUID, 138 }, 139 }}, 140 }} { 141 if !assert.ProtoElementsMatch(tc.A, tc.B) { 142 t.Errorf("%s: expected equality", tc.Name) 143 } 144 } 145 }