-
Notifications
You must be signed in to change notification settings - Fork 14
/
testing_snapshot.sk.go
128 lines (110 loc) · 3.2 KB
/
testing_snapshot.sk.go
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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
// Code generated by solo-kit. DO NOT EDIT.
package v2alpha1
import (
"fmt"
"hash"
"hash/fnv"
"log"
testing_solo_io "github.com/solo-io/solo-kit/test/mocks/v1"
"github.com/rotisserie/eris"
"github.com/solo-io/go-utils/hashutils"
"go.uber.org/zap"
)
type TestingSnapshot struct {
Mocks MockResourceList
Fcars FrequentlyChangingAnnotationsResourceList
Fakes testing_solo_io.FakeResourceList
}
func (s TestingSnapshot) Clone() TestingSnapshot {
return TestingSnapshot{
Mocks: s.Mocks.Clone(),
Fcars: s.Fcars.Clone(),
Fakes: s.Fakes.Clone(),
}
}
func (s TestingSnapshot) Hash(hasher hash.Hash64) (uint64, error) {
if hasher == nil {
hasher = fnv.New64()
}
if _, err := s.hashMocks(hasher); err != nil {
return 0, err
}
if _, err := s.hashFcars(hasher); err != nil {
return 0, err
}
if _, err := s.hashFakes(hasher); err != nil {
return 0, err
}
return hasher.Sum64(), nil
}
func (s TestingSnapshot) hashMocks(hasher hash.Hash64) (uint64, error) {
return hashutils.HashAllSafe(hasher, s.Mocks.AsInterfaces()...)
}
func (s TestingSnapshot) hashFcars(hasher hash.Hash64) (uint64, error) {
clonedList := s.Fcars.Clone()
for _, v := range clonedList {
v.Metadata.Annotations = nil
}
return hashutils.HashAllSafe(hasher, clonedList.AsInterfaces()...)
}
func (s TestingSnapshot) hashFakes(hasher hash.Hash64) (uint64, error) {
return hashutils.HashAllSafe(hasher, s.Fakes.AsInterfaces()...)
}
func (s TestingSnapshot) HashFields() []zap.Field {
var fields []zap.Field
hasher := fnv.New64()
MocksHash, err := s.hashMocks(hasher)
if err != nil {
log.Println(eris.Wrapf(err, "error hashing, this should never happen"))
}
fields = append(fields, zap.Uint64("mocks", MocksHash))
FcarsHash, err := s.hashFcars(hasher)
if err != nil {
log.Println(eris.Wrapf(err, "error hashing, this should never happen"))
}
fields = append(fields, zap.Uint64("fcars", FcarsHash))
FakesHash, err := s.hashFakes(hasher)
if err != nil {
log.Println(eris.Wrapf(err, "error hashing, this should never happen"))
}
fields = append(fields, zap.Uint64("fakes", FakesHash))
snapshotHash, err := s.Hash(hasher)
if err != nil {
log.Println(eris.Wrapf(err, "error hashing, this should never happen"))
}
return append(fields, zap.Uint64("snapshotHash", snapshotHash))
}
type TestingSnapshotStringer struct {
Version uint64
Mocks []string
Fcars []string
Fakes []string
}
func (ss TestingSnapshotStringer) String() string {
s := fmt.Sprintf("TestingSnapshot %v\n", ss.Version)
s += fmt.Sprintf(" Mocks %v\n", len(ss.Mocks))
for _, name := range ss.Mocks {
s += fmt.Sprintf(" %v\n", name)
}
s += fmt.Sprintf(" Fcars %v\n", len(ss.Fcars))
for _, name := range ss.Fcars {
s += fmt.Sprintf(" %v\n", name)
}
s += fmt.Sprintf(" Fakes %v\n", len(ss.Fakes))
for _, name := range ss.Fakes {
s += fmt.Sprintf(" %v\n", name)
}
return s
}
func (s TestingSnapshot) Stringer() TestingSnapshotStringer {
snapshotHash, err := s.Hash(nil)
if err != nil {
log.Println(eris.Wrapf(err, "error hashing, this should never happen"))
}
return TestingSnapshotStringer{
Version: snapshotHash,
Mocks: s.Mocks.NamespacesDotNames(),
Fcars: s.Fcars.NamespacesDotNames(),
Fakes: s.Fakes.NamespacesDotNames(),
}
}