-
Notifications
You must be signed in to change notification settings - Fork 0
/
util_test.go
49 lines (44 loc) · 1.3 KB
/
util_test.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
package main
import (
"encoding/json"
"testing"
)
func TestAvroEncode(t *testing.T) {
// Encode our blob.
orig := []byte(`{
"wallet_id": "655f6eab-a6c0-4712-9d57-d3ef09a423e9",
"service": "ADS",
"signal": "ANON_IP_ADDRS",
"score": 0,
"justification": "{\"keyid\":\"fd1ecf36-f5f5-4186-888d-d3ef09a423e9\",\"addrs\":[\"1.1.1.1\",\"2.2.2.2\"]}",
"created_at":"2021-12-16T12:00:00.00+00:20"
}`)
encoded, err := avroEncode(ourCodec, orig)
if err != nil {
t.Fatalf("Failed to Avro-encode data: %v", err)
}
// Now try to decode it.
native, _, err := ourCodec.NativeFromBinary(encoded)
if err != nil {
t.Fatalf("Failed to get native from binary: %v", err)
}
decoded, err := ourCodec.TextualFromNative(nil, native)
if err != nil {
t.Fatalf("Failed to get textual from native: %v", err)
}
origStruct := kafkaMessage{}
decodedStruct := kafkaMessage{}
if err := json.Unmarshal(orig, &origStruct); err != nil {
t.Fatalf("Failed to unmarshal JSON: %v", err)
}
if err := json.Unmarshal(decoded, &decodedStruct); err != nil {
t.Fatalf("Failed to unmarshal JSON: %v", err)
}
// Did we end up with the same struct?
if origStruct != decodedStruct {
t.Fatalf("Expected\n%v\nbut got\n%v", origStruct, decodedStruct)
}
}
func TestMaxSoftFdLimit(t *testing.T) {
assertEqual(t, maxSoftFdLimit(), nil)
}