3
0

Shaping tests & post tweaks

This commit is contained in:
Tomaž Jerman
2020-11-26 19:31:09 +01:00
parent 10b300328d
commit a0b7716244
13 changed files with 280 additions and 5 deletions

View File

@@ -103,3 +103,7 @@ func (cr *reader) Next() (map[string]string, error) {
return mr, nil
}
func (cr *reader) Count() uint64 {
return cr.count
}

View File

@@ -0,0 +1,58 @@
package csv
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.csv", 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.Equal([]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)
})
}

4
pkg/envoy/csv/testdata/records_1.csv vendored Normal file
View File

@@ -0,0 +1,4 @@
id,c1,c2,c3
1,c1.v1,c2.v1,c3.v1
2,c1.v2,c2.v2,c3.v2
3,c1.v3,c2.v3,c3.v3
1 id c1 c2 c3
2 1 c1.v1 c2.v1 c3.v1
3 2 c1.v2 c2.v2 c3.v2
4 3 c1.v3 c2.v3 c3.v3