i'll got with this I guess

This commit is contained in:
2026-03-05 18:55:00 +00:00
parent f8d483dd62
commit 9b10042112
2 changed files with 120 additions and 2 deletions
+67
View File
@@ -0,0 +1,67 @@
package telemetry
import (
"bytes"
"math"
"testing"
)
func Test_TelemetryField(t *testing.T) {
type TFTest struct {
name string
tf TelemetryField
expect []byte
}
tests := []TFTest{
{
name: "test_max_uint8",
tf: TelemetryField{
Type: DataTypeUINT8,
Value: uint8(math.MaxUint8),
},
expect: []byte{0x00, 0xFF},
},
{
name: "test_max_int8",
tf: TelemetryField{
Type: DataTypeINT8,
Value: int8(math.MaxInt8),
},
expect: []byte{0x01, 0x7F},
},
{
name: "test_max_uint16",
tf: TelemetryField{
Type: DataTypeUINT16,
Value: uint16(math.MaxUint16),
},
expect: []byte{0x02, 0xFF, 0xFF},
},
{
name: "test_max_int16",
tf: TelemetryField{
Type: DataTypeINT16,
Value: int16(math.MaxInt16),
},
expect: []byte{0x03, 0xFF, 0x7F},
},
{
name: "test_string",
tf: TelemetryField{
Type: DataTypeSTRING,
Value: "a cool string!",
},
expect: []byte{0x04, 0x0E, 0x61, 0x20, 0x63, 0x6F, 0x6F, 0x6C, 0x20, 0x73,
0x74, 0x72, 0x69, 0x6E, 0x67, 0x21},
},
}
for _, test := range tests {
result := test.tf.Pack()
if !bytes.Equal(result, test.expect) {
t.Errorf("\nTest: %s\nExpected: %v\nGot: %v\n", test.name, test.expect, result)
}
}
}