summaryrefslogtreecommitdiff
path: root/src/mongo/gotools/src/github.com/mongodb/mongo-tools/vendor/github.com/google/go-cmp/cmp/internal/teststructs/project3.go
blob: 957d093c72a69b3d2d592c8efdec21dadc0d85a3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
// Copyright 2017, The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE.md file.

package teststructs

import (
	"sync"

	pb "github.com/google/go-cmp/cmp/internal/testprotos"
)

// This is an sanitized example of equality from a real use-case.
// The original equality function was as follows:
/*
func equalDirt(x, y *Dirt) bool {
	if !reflect.DeepEqual(x.table, y.table) ||
		!reflect.DeepEqual(x.ts, y.ts) ||
		x.Discord != y.Discord ||
		!pb.Equal(&x.Proto, &y.Proto) ||
		len(x.wizard) != len(y.wizard) ||
		len(x.sadistic) != len(y.sadistic) ||
		x.lastTime != y.lastTime {
		return false
	}
	for k, vx := range x.wizard {
		vy, ok := y.wizard[k]
		if !ok || !pb.Equal(vx, vy) {
			return false
		}
	}
	for k, vx := range x.sadistic {
		vy, ok := y.sadistic[k]
		if !ok || !pb.Equal(vx, vy) {
			return false
		}
	}
	return true
}
*/

type FakeMutex struct {
	sync.Locker
	x struct{}
}

type Dirt struct {
	table    Table // Always concrete type of MockTable
	ts       Timestamp
	Discord  DiscordState
	Proto    pb.Dirt
	wizard   map[string]*pb.Wizard
	sadistic map[string]*pb.Sadistic
	lastTime int64
	mu       FakeMutex
}

type DiscordState int

type Timestamp int64

func (d *Dirt) SetTable(t Table)                      { d.table = t }
func (d *Dirt) SetTimestamp(t Timestamp)              { d.ts = t }
func (d *Dirt) SetWizard(m map[string]*pb.Wizard)     { d.wizard = m }
func (d *Dirt) SetSadistic(m map[string]*pb.Sadistic) { d.sadistic = m }
func (d *Dirt) SetLastTime(t int64)                   { d.lastTime = t }

type Table interface {
	Operation1() error
	Operation2() error
	Operation3() error
}

type MockTable struct {
	state []string
}

func CreateMockTable(s []string) *MockTable { return &MockTable{s} }
func (mt *MockTable) Operation1() error     { return nil }
func (mt *MockTable) Operation2() error     { return nil }
func (mt *MockTable) Operation3() error     { return nil }
func (mt *MockTable) State() []string       { return mt.state }