Skip to content

Commit

Permalink
Simpify some Go tests with zson.MustParseValue (#5011)
Browse files Browse the repository at this point in the history
  • Loading branch information
nwt authored Jan 30, 2024
1 parent 4eba82a commit ec69d94
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 18 deletions.
12 changes: 2 additions & 10 deletions api/queryio/zjson_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,16 @@ package queryio_test

import (
"bytes"
"strings"
"testing"

"github.com/brimdata/zed"
"github.com/brimdata/zed/api"
"github.com/brimdata/zed/api/queryio"
"github.com/brimdata/zed/zio/zsonio"
"github.com/brimdata/zed/zson"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)

func mkRecord(t *testing.T, s string) zed.Value {
r := zsonio.NewReader(zed.NewContext(), strings.NewReader(s))
rec, err := r.Read()
require.NoError(t, err)
return *rec
}

func TestZJSONWriter(t *testing.T) {
const record = `{x:1}`
const expected = `
Expand All @@ -32,7 +24,7 @@ func TestZJSONWriter(t *testing.T) {
w := queryio.NewZJSONWriter(&buf)
err := w.WriteControl(api.QueryChannelSet{ChannelID: 1})
require.NoError(t, err)
err = w.Write(mkRecord(t, record))
err = w.Write(zson.MustParseValue(zed.NewContext(), record))
require.NoError(t, err)
err = w.WriteControl(api.QueryChannelEnd{ChannelID: 1})
require.NoError(t, err)
Expand Down
4 changes: 1 addition & 3 deletions complex_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,7 @@ import (

func TestRecordAccessNamed(t *testing.T) {
const input = `{foo:"hello" (=zfile),bar:true (=zbool)} (=0)`
reader := zsonio.NewReader(zed.NewContext(), strings.NewReader(input))
rec, err := reader.Read()
require.NoError(t, err)
rec := zson.MustParseValue(zed.NewContext(), input)
s := rec.Deref("foo").AsString()
assert.Equal(t, s, "hello")
b := rec.Deref("bar").AsBool()
Expand Down
7 changes: 2 additions & 5 deletions zson/marshal_zng_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import (
"github.com/brimdata/zed/pkg/nano"
"github.com/brimdata/zed/zio"
"github.com/brimdata/zed/zio/zngio"
"github.com/brimdata/zed/zio/zsonio"
"github.com/brimdata/zed/zson"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
Expand Down Expand Up @@ -185,11 +184,9 @@ func TestUnmarshalRecord(t *testing.T) {
const expected = `{top:{T2f1:{T3f1:1(int32),T3f2:1.(float32)},T2f2:"t2f2-string1"}}`
require.Equal(t, expected, zson.FormatValue(rec))

val, err := zsonio.NewReader(zed.NewContext(), strings.NewReader(expected)).Read()
require.NoError(t, err)

val := zson.MustParseValue(zed.NewContext(), expected)
var v2 T1
err = zson.UnmarshalZNG(*val, &v2)
err = zson.UnmarshalZNG(val, &v2)
require.NoError(t, err)
require.Equal(t, v1, v2)

Expand Down

0 comments on commit ec69d94

Please sign in to comment.