-
Notifications
You must be signed in to change notification settings - Fork 153
/
operations.go
45 lines (38 loc) · 1.12 KB
/
operations.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
package querytest
import (
"encoding/json"
"testing"
"github.com/google/go-cmp/cmp"
"github.com/google/go-cmp/cmp/cmpopts"
"github.com/influxdata/flux"
"github.com/influxdata/flux/semantic/semantictest"
"github.com/influxdata/flux/stdlib/universe"
)
func OperationMarshalingTestHelper(t *testing.T, data []byte, expOp *flux.Operation) {
t.Helper()
opts := append(
semantictest.CmpOptions,
cmp.AllowUnexported(universe.JoinOpSpec{}),
cmpopts.IgnoreUnexported(universe.JoinOpSpec{}),
)
// Ensure we can properly unmarshal a spec
gotOp := new(flux.Operation)
if err := json.Unmarshal(data, gotOp); err != nil {
t.Fatal(err)
}
if !cmp.Equal(gotOp, expOp, opts...) {
t.Errorf("unexpected operation -want/+got %s", cmp.Diff(expOp, gotOp, opts...))
}
// Marshal the spec and ensure we can unmarshal it again.
data, err := json.Marshal(expOp)
if err != nil {
t.Fatal(err)
}
gotOp = new(flux.Operation)
if err := json.Unmarshal(data, gotOp); err != nil {
t.Fatal(err)
}
if !cmp.Equal(gotOp, expOp, opts...) {
t.Errorf("unexpected operation after marshalling -want/+got %s", cmp.Diff(expOp, gotOp, opts...))
}
}