influxdb/query/querytest/compile.go

49 lines
1.1 KiB
Go
Raw Normal View History

2018-05-21 21:13:54 +00:00
package querytest
import (
"context"
"testing"
"time"
2018-05-21 21:13:54 +00:00
"github.com/google/go-cmp/cmp"
"github.com/google/go-cmp/cmp/cmpopts"
2018-05-21 21:20:06 +00:00
"github.com/influxdata/platform/query"
"github.com/influxdata/platform/query/functions"
2018-05-21 21:20:06 +00:00
"github.com/influxdata/platform/query/semantic/semantictest"
2018-05-21 21:13:54 +00:00
)
type NewQueryTestCase struct {
Name string
Raw string
Want *query.Spec
WantErr bool
}
var opts = append(
semantictest.CmpOptions,
cmp.AllowUnexported(query.Spec{}),
2018-07-06 21:38:05 +00:00
cmp.AllowUnexported(functions.JoinOpSpec{}),
2018-05-21 21:13:54 +00:00
cmpopts.IgnoreUnexported(query.Spec{}),
2018-07-06 21:38:05 +00:00
cmpopts.IgnoreUnexported(functions.JoinOpSpec{}),
2018-05-21 21:13:54 +00:00
)
func NewQueryTestHelper(t *testing.T, tc NewQueryTestCase) {
t.Helper()
now := time.Now().UTC()
got, err := query.Compile(context.Background(), tc.Raw, now)
2018-05-21 21:13:54 +00:00
if (err != nil) != tc.WantErr {
2018-06-08 20:02:59 +00:00
t.Errorf("query.NewQuery() error = %v, wantErr %v", err, tc.WantErr)
2018-05-21 21:13:54 +00:00
return
}
if tc.WantErr {
return
}
if tc.Want != nil {
tc.Want.Now = now
}
2018-05-21 21:13:54 +00:00
if !cmp.Equal(tc.Want, got, opts...) {
2018-06-08 20:02:59 +00:00
t.Errorf("query.NewQuery() = -want/+got %s", cmp.Diff(tc.Want, got, opts...))
2018-05-21 21:13:54 +00:00
}
}