1// Copyright 2017, The Go Authors. All rights reserved. 2// Use of this source code is governed by a BSD-style 3// license that can be found in the LICENSE file. 4 5package teststructs 6 7import ( 8 "sync" 9 10 pb "github.com/google/go-cmp/cmp/internal/testprotos" 11) 12 13// This is an sanitized example of equality from a real use-case. 14// The original equality function was as follows: 15/* 16func equalDirt(x, y *Dirt) bool { 17 if !reflect.DeepEqual(x.table, y.table) || 18 !reflect.DeepEqual(x.ts, y.ts) || 19 x.Discord != y.Discord || 20 !pb.Equal(&x.Proto, &y.Proto) || 21 len(x.wizard) != len(y.wizard) || 22 len(x.sadistic) != len(y.sadistic) || 23 x.lastTime != y.lastTime { 24 return false 25 } 26 for k, vx := range x.wizard { 27 vy, ok := y.wizard[k] 28 if !ok || !pb.Equal(vx, vy) { 29 return false 30 } 31 } 32 for k, vx := range x.sadistic { 33 vy, ok := y.sadistic[k] 34 if !ok || !pb.Equal(vx, vy) { 35 return false 36 } 37 } 38 return true 39} 40*/ 41 42type FakeMutex struct { 43 sync.Locker 44 x struct{} 45} 46 47type Dirt struct { 48 table Table // Always concrete type of MockTable 49 ts Timestamp 50 Discord DiscordState 51 Proto pb.Dirt 52 wizard map[string]*pb.Wizard 53 sadistic map[string]*pb.Sadistic 54 lastTime int64 55 mu FakeMutex 56} 57 58type DiscordState int 59 60type Timestamp int64 61 62func (d *Dirt) SetTable(t Table) { d.table = t } 63func (d *Dirt) SetTimestamp(t Timestamp) { d.ts = t } 64func (d *Dirt) SetWizard(m map[string]*pb.Wizard) { d.wizard = m } 65func (d *Dirt) SetSadistic(m map[string]*pb.Sadistic) { d.sadistic = m } 66func (d *Dirt) SetLastTime(t int64) { d.lastTime = t } 67 68type Table interface { 69 Operation1() error 70 Operation2() error 71 Operation3() error 72} 73 74type MockTable struct { 75 state []string 76} 77 78func CreateMockTable(s []string) *MockTable { return &MockTable{s} } 79func (mt *MockTable) Operation1() error { return nil } 80func (mt *MockTable) Operation2() error { return nil } 81func (mt *MockTable) Operation3() error { return nil } 82func (mt *MockTable) State() []string { return mt.state } 83