featurebase/encoding/proto/proto_test.go
Seebs 16ccbc461a Drop the ingest subpackage and related endpoints.
The internal/ingest and internal/schema endpoints were developed with
intent that they'd be the primary interface new users would work with,
because they were Easy To Use, and did not require any kind of setup,
the counterpoint being that ingest done this way had performance issues
because it ended up with huge amounts of JSON parsing to reformat
things into our native format. But this was understood to be the price
of providing a new-user-friendly JSON ingest experience.

A year later, we have no evidence that it's ever been used. We never
even moved it out of the `/internal` path. It's a lot of very complex
fiddly code and we don't seem to be using it, and at this point, our
anticipation is that if we really need something, we'll use CSV, which
we already have working, or something in the new SQL code. Either way,
we don't seem to be using this.
2022-11-01 13:08:44 -05:00

83 lines
2.7 KiB
Go

// Copyright 2021 Molecula Corp. All rights reserved.
package proto
import (
"reflect"
"testing"
pilosa "github.com/molecula/featurebase/v3"
"github.com/molecula/featurebase/v3/pb"
)
func testOneRoundTrip(t *testing.T, s pilosa.Serializer, obj pilosa.Message, expectedMarshalErr error, expectedUnmarshalErr error, expectedMismatchErr error) {
repr, err := s.Marshal(obj)
if err != nil {
if expectedMarshalErr == nil {
t.Fatalf("unexpected marshalling error %q", err.Error())
}
if err.Error() != expectedMarshalErr.Error() {
t.Fatalf("expecting marshalling error %q, got %q", expectedMarshalErr.Error(), err.Error())
}
} else {
if expectedMarshalErr != nil {
t.Fatalf("expected marshalling error %q, got no error", expectedMarshalErr.Error())
}
}
obj2 := reflect.New(reflect.TypeOf(obj).Elem()).Interface()
err = s.Unmarshal(repr, obj2)
if err != nil {
if expectedUnmarshalErr == nil {
t.Fatalf("unexpected unmarshalling error %q", err.Error())
}
if err.Error() != expectedUnmarshalErr.Error() {
t.Fatalf("expecting unmarshalling error %q, got %q", expectedUnmarshalErr.Error(), err.Error())
}
} else {
if expectedUnmarshalErr != nil {
t.Fatalf("expected unmarshalling error %q, got no error", expectedUnmarshalErr.Error())
}
}
if !reflect.DeepEqual(obj, obj2) {
t.Fatalf("serialization round trip failed for %T:\nexpected %#v\ngot %#v", obj, obj, obj2)
}
}
func TestEncodeDecodeDistinctTimestamp(t *testing.T) {
s := Serializer{}
pbTime := pb.DistinctTimestamp{
Values: []string{"this", "is", "fake", "timestamp", "values"},
Name: "pbtime",
}
piloTime := pilosa.DistinctTimestamp{
Values: []string{"this", "is", "fake", "timestamp", "values"},
Name: "pbtime",
}
decoded := s.decodeDistinctTimestamp(&pbTime)
if !reflect.DeepEqual(decoded, piloTime) {
t.Errorf("failed to decode DistinctTimestamp. expected %v got %v", piloTime, decoded)
}
encoded := s.encodeDistinctTimestamp(piloTime)
if !reflect.DeepEqual(encoded, &pbTime) {
t.Errorf("failed to encode DistinctTimestamp. expected %v got %v", &pbTime, encoded)
}
}
func TestDecodeQueryResult(t *testing.T) {
t.Run("DistinctTimestamp", func(t *testing.T) {
pbTime := pb.DistinctTimestamp{
Values: []string{"this", "is", "fake", "timestamp", "values"},
Name: "pbtime",
}
piloTime := pilosa.DistinctTimestamp{
Values: []string{"this", "is", "fake", "timestamp", "values"},
Name: "pbtime",
}
q := &pb.QueryResult{Type: queryResultTypeDistinctTimestamp, DistinctTimestamp: &pbTime}
s := Serializer{}
decoded := s.decodeQueryResult(q)
if !reflect.DeepEqual(decoded, piloTime) {
t.Errorf("failed to decode DistinctTimestamp. expected %v got %v", piloTime, decoded)
}
})
}