Some checks failed
SonarQube / SonarQube (push) Failing after 5m28s
E2e test on main branch push / server and client test (map[name:admin port:8080]) (push) Failing after 3m33s
Server and lib tests / Library test (js) (push) Failing after 1m36s
Server and lib tests / Library test (vue) (push) Successful in 2m24s
Server and lib tests / Web client test (admin) (push) Successful in 2m52s
Server and lib tests / Web client test (compose) (push) Successful in 3m23s
Server and lib tests / Web client test (discovery) (push) Successful in 2m49s
Server and lib tests / Web client test (one) (push) Successful in 2m52s
Server and lib tests / Web client test (privacy) (push) Successful in 2m44s
Server and lib tests / Web client test (reporter) (push) Successful in 2m56s
Server and lib tests / Web client test (workflow) (push) Successful in 3m0s
Server and lib tests / Server tests (push) Failing after 4m55s
E2e test on main branch push / notify-failure (push) Failing after 9s
Server and lib tests / Send matrix testing notification (push) Successful in 2s
Mark stale issues and pull requests / stale (push) Successful in 40s
59 lines
1.2 KiB
Go
59 lines
1.2 KiB
Go
package json
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"os"
|
|
"testing"
|
|
|
|
"github.com/cortezaproject/corteza/server/pkg/envoy"
|
|
"github.com/cortezaproject/corteza/server/pkg/envoy/resource"
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
func parseDocument(ctx context.Context, name string) (*resource.ResourceDataset, error) {
|
|
path := fmt.Sprintf("testdata/%s.jsonl", name)
|
|
f, err := os.Open(path)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer f.Close()
|
|
|
|
cd := Decoder()
|
|
ii, err := cd.Decode(ctx, f, &envoy.DecoderOpts{
|
|
Name: name,
|
|
Path: path,
|
|
})
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
rd, _ := ii[0].(*resource.ResourceDataset)
|
|
return rd, nil
|
|
}
|
|
|
|
func TestDecoder(t *testing.T) {
|
|
ctx := context.Background()
|
|
|
|
t.Run("doc 1", func(t *testing.T) {
|
|
req := require.New(t)
|
|
|
|
ds, err := parseDocument(ctx, "records_1")
|
|
req.NoError(err)
|
|
req.NotNil(ds)
|
|
req.Equal(resource.MakeIdentifiers("records_1"), ds.Identifiers())
|
|
req.Subset([]string{"id", "c1", "c2", "c3"}, ds.P.Fields())
|
|
req.Equal(uint64(3), ds.P.Count())
|
|
|
|
for i := 0; i < 3; i++ {
|
|
n, err := ds.P.Next()
|
|
req.NoError(err)
|
|
req.NotNil(n)
|
|
|
|
req.Len(n, 4)
|
|
}
|
|
n, err := ds.P.Next()
|
|
req.Nil(n)
|
|
req.Nil(err)
|
|
})
|
|
}
|