This repository has been archived by the owner on Aug 23, 2023. It is now read-only.
/
key.go
51 lines (43 loc) · 1.1 KB
/
key.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
package test
import (
"fmt"
"reflect"
"github.com/grafana/metrictank/schema"
)
func GetAMKey(suffix int) schema.AMKey {
return schema.AMKey{
MKey: GetMKey(suffix),
}
}
func GetMKey(suffix int) schema.MKey {
s := uint32(suffix)
return schema.MKey{
Key: [16]byte{0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, byte(s >> 24), byte(s >> 16), byte(s >> 8), byte(s)},
}
}
func KeyToInt(key schema.MKey) int {
return int(uint32(key.Key[15]) + uint32(key.Key[14])<<8 + uint32(key.Key[13])<<16 + uint32(key.Key[12])<<24)
}
func MustMKeyFromString(id string) schema.MKey {
mkey, err := schema.MKeyFromString(id)
if err != nil {
panic(err)
}
return mkey
}
func ContainsMKey(list []schema.MKey, subject schema.MKey) bool {
for _, v := range list {
if reflect.DeepEqual(v, subject) {
return true
}
}
return false
}
func ShouldContainMKey(actual interface{}, expected ...interface{}) string {
list := expected[0].([]schema.MKey)
subject := actual.(schema.MKey)
if !ContainsMKey(list, subject) {
return fmt.Sprintf("slice of MKey's did not contain %v", subject)
}
return ""
}