TestEncodeMsgPack verifies basic msgpack encoding functionality
(t *testing.T)
| 8 | |
| 9 | // TestEncodeMsgPack verifies basic msgpack encoding functionality |
| 10 | func 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 |
| 59 | func TestDecodeMsgPack(t *testing.T) { |
nothing calls this directly
no test coverage detected