MCPcopy Index your code
hub / github.com/CrowdStrike/csproto / TestEncodeString

Function TestEncodeString

encoder_test.go:57–84  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

55}
56
57func TestEncodeString(t *testing.T) {
58 cases := []struct {
59 name string
60 fieldNum int
61 v string
62 expected []byte
63 }{
64 {
65 name: "empty string",
66 fieldNum: 1,
67 v: "",
68 expected: []byte{0xA, 0x0},
69 },
70 {
71 name: "non-empty string",
72 fieldNum: 2,
73 v: "this is a test",
74 expected: []byte{0x12, 0xE, 0x74, 0x68, 0x69, 0x73, 0x20, 0x69, 0x73, 0x20, 0x61, 0x20, 0x74, 0x65, 0x73, 0x74},
75 },
76 }
77 for _, tc := range cases {
78 t.Run(tc.name, func(t *testing.T) {
79 dest := make([]byte, len(tc.expected))
80 csproto.NewEncoder(dest).EncodeString(tc.fieldNum, tc.v)
81 assert.Equal(t, tc.expected, dest)
82 })
83 }
84}
85
86func TestEncodeBytes(t *testing.T) {
87 cases := []struct {

Callers

nothing calls this directly

Calls 2

NewEncoderFunction · 0.92
EncodeStringMethod · 0.80

Tested by

no test coverage detected