MCPcopy Create free account
hub / github.com/frain-dev/convoy / TestEncodeMsgPack

Function TestEncodeMsgPack

pkg/msgpack/msgpack_test.go:10–56  ·  view source on GitHub ↗

TestEncodeMsgPack verifies basic msgpack encoding functionality

(t *testing.T)

Source from the content-addressed store, hash-verified

8
9// TestEncodeMsgPack verifies basic msgpack encoding functionality
10func TestEncodeMsgPack(t *testing.T) {
11 type testStruct struct {
12 Name string `json:"name"`
13 Value int `json:"value"`
14 }
15
16 tests := []struct {
17 name string
18 payload interface{}
19 wantErr bool
20 }{
21 {
22 name: "encode simple struct",
23 payload: testStruct{
24 Name: "test",
25 Value: 42,
26 },
27 wantErr: false,
28 },
29 {
30 name: "encode map",
31 payload: map[string]interface{}{
32 "key1": "value1",
33 "key2": 123,
34 },
35 wantErr: false,
36 },
37 {
38 name: "encode string",
39 payload: "test string",
40 wantErr: false,
41 },
42 }
43
44 for _, tt := range tests {
45 t.Run(tt.name, func(t *testing.T) {
46 result, err := EncodeMsgPack(tt.payload)
47 if (err != nil) != tt.wantErr {
48 t.Errorf("EncodeMsgPack() error = %v, wantErr %v", err, tt.wantErr)
49 return
50 }
51 if !tt.wantErr && len(result) == 0 {
52 t.Error("EncodeMsgPack() returned empty byte slice")
53 }
54 })
55 }
56}
57
58// TestDecodeMsgPack verifies msgpack decoding functionality
59func TestDecodeMsgPack(t *testing.T) {

Callers

nothing calls this directly

Calls 4

EncodeMsgPackFunction · 0.85
ErrorfMethod · 0.65
ErrorMethod · 0.65
RunMethod · 0.45

Tested by

no test coverage detected