mirror of
https://github.com/hanzoai/tasks.git
synced 2026-10-04 02:04:03 +00:00
## What changed?
<!-- Describe what has changed in this PR -->
Remove license header from every file. Because it is really hard to
follow in this PR here is the summary:
1. License header is removed from all `.go` and `.proto` files
:fireworks::fireworks:🎆.
2. `LICENSE` file in the root directory has only Temporal and Uber
copyrights.
3. 5 other `LICENSE` files added to the packages which have copyrights
different from Temporal and Uber: Datadog, Xargin, "Mat Ryer, Tyler
Bunnell and contributors".
4. `license_file` flag is removed from all code generation tools.
5. `copyright_file` flag is removed from `go:generate mockgen`
directive.
6. All copyright related targets are removed from `Makefile`.
7. Updated Temporal copyright year to 2025 everywhere.
## Why?
<!-- Tell your future self why have you made these changes -->
I double checked with legal department that it is not needed to have
license header in every file. One file per repo is enough. I put all
copyrights to the root `LICENSE` file and removed header from all other
files. Also updated tools and `Makefile`.
123 lines
2.9 KiB
Go
123 lines
2.9 KiB
Go
// Assert wraps testify's require package with useful helpers
|
|
package protoassert
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
"github.com/google/go-cmp/cmp"
|
|
"github.com/stretchr/testify/assert"
|
|
"go.temporal.io/api/temporalproto"
|
|
"google.golang.org/protobuf/proto"
|
|
"google.golang.org/protobuf/testing/protocmp"
|
|
)
|
|
|
|
type helper interface {
|
|
Helper()
|
|
}
|
|
|
|
type ProtoAssertions struct {
|
|
t assert.TestingT
|
|
}
|
|
|
|
func New(t assert.TestingT) ProtoAssertions {
|
|
return ProtoAssertions{t}
|
|
}
|
|
|
|
// ProtoEqual compares two proto.Message objects for equality
|
|
func ProtoEqual(t assert.TestingT, a proto.Message, b proto.Message) bool {
|
|
if th, ok := t.(helper); ok {
|
|
th.Helper()
|
|
}
|
|
if diff := cmp.Diff(a, b, protocmp.Transform()); diff != "" {
|
|
return assert.Fail(t, fmt.Sprintf("Proto mismatch (-want +got):\n%v", diff))
|
|
}
|
|
return true
|
|
}
|
|
|
|
func NotProtoEqual(t assert.TestingT, a proto.Message, b proto.Message) bool {
|
|
if th, ok := t.(helper); ok {
|
|
th.Helper()
|
|
}
|
|
if diff := cmp.Diff(a, b, protocmp.Transform()); diff == "" {
|
|
return assert.Fail(t, "Expected protos to differ but they did not")
|
|
}
|
|
return true
|
|
}
|
|
|
|
// ProtoSliceEqual compares elements in a slice of proto.Message.
|
|
// This is not a method on the suite type because methods cannot have
|
|
// generic parameters and slice casting (say from []historyEvent) to
|
|
// []proto.Message is impossible
|
|
func ProtoSliceEqual[T proto.Message](t assert.TestingT, a []T, b []T) bool {
|
|
if th, ok := t.(helper); ok {
|
|
th.Helper()
|
|
}
|
|
if len(a) != len(b) {
|
|
return false
|
|
}
|
|
for i := 0; i < len(a); i++ {
|
|
if diff := cmp.Diff(a[i], b[i], protocmp.Transform()); diff != "" {
|
|
return assert.Fail(t, fmt.Sprintf("Proto mismatch at index %d (-want +got):\n%v", i, diff))
|
|
}
|
|
}
|
|
|
|
return true
|
|
}
|
|
|
|
// ProtoElementsMatch behaves like assert.ElementsMatch except in that it works for
|
|
// google/protobuf-generated structs
|
|
func ProtoElementsMatch(t assert.TestingT, a any, b any, msgAndArgs ...any) bool {
|
|
if th, ok := t.(helper); ok {
|
|
th.Helper()
|
|
}
|
|
|
|
if isEmpty(a) && isEmpty(b) {
|
|
return true
|
|
}
|
|
|
|
extraA, extraB := diffLists(a, b)
|
|
if len(extraA) == 0 && len(extraB) == 0 {
|
|
return true
|
|
}
|
|
|
|
return assert.Fail(t, formatListDiff(a, b, extraA, extraB), msgAndArgs...)
|
|
}
|
|
|
|
func DeepEqual(t assert.TestingT, a any, b any) bool {
|
|
if th, ok := t.(helper); ok {
|
|
th.Helper()
|
|
}
|
|
|
|
return temporalproto.DeepEqual(a, b)
|
|
}
|
|
|
|
func (x ProtoAssertions) ProtoEqual(a proto.Message, b proto.Message) bool {
|
|
if th, ok := x.t.(helper); ok {
|
|
th.Helper()
|
|
}
|
|
return ProtoEqual(x.t, a, b)
|
|
}
|
|
|
|
func (x ProtoAssertions) NotProtoEqual(a proto.Message, b proto.Message) bool {
|
|
if th, ok := x.t.(helper); ok {
|
|
th.Helper()
|
|
}
|
|
return NotProtoEqual(x.t, a, b)
|
|
}
|
|
|
|
func (x ProtoAssertions) DeepEqual(a any, b any) bool {
|
|
if th, ok := x.t.(helper); ok {
|
|
th.Helper()
|
|
}
|
|
|
|
return temporalproto.DeepEqual(a, b)
|
|
}
|
|
|
|
func (x ProtoAssertions) ProtoElementsMatch(a any, b any) bool {
|
|
if th, ok := x.t.(helper); ok {
|
|
th.Helper()
|
|
}
|
|
|
|
return ProtoElementsMatch(x.t, a, b)
|
|
}
|