Files
tasks/service/worker/scheduler/query_test.go
Alex ShtinandGitHub 8e8f1b0f7c Remove license header from every file (#7689)
## What changed?
<!-- Describe what has changed in this PR -->
Remove license header from every file. Because it is really hard to
follow in this PR here is the summary:
1. License header is removed from all `.go` and `.proto` files
:fireworks::fireworks:🎆.
2. `LICENSE` file in the root directory has only Temporal and Uber
copyrights.
3. 5 other `LICENSE` files added to the packages which have copyrights
different from Temporal and Uber: Datadog, Xargin, "Mat Ryer, Tyler
Bunnell and contributors".
4. `license_file` flag is removed from all code generation tools.
5. `copyright_file` flag is removed from `go:generate mockgen`
directive.
6. All copyright related targets are removed from `Makefile`.
7. Updated Temporal copyright year to 2025 everywhere.

## Why?
<!-- Tell your future self why have you made these changes -->
I double checked with legal department that it is not needed to have
license header in every file. One file per repo is enough. I put all
copyrights to the root `LICENSE` file and removed header from all other
files. Also updated tools and `Makefile`.
2025-05-01 18:50:21 -07:00

206 lines
5.6 KiB
Go

package scheduler
import (
"testing"
"github.com/stretchr/testify/require"
"go.temporal.io/api/serviceerror"
"go.temporal.io/server/common/namespace"
"go.temporal.io/server/common/persistence/visibility/store/query"
"go.temporal.io/server/common/searchattribute"
)
const (
testNamespace = namespace.Name("test-namespace")
)
func TestFieldNameAggInterceptor(t *testing.T) {
s := require.New(t)
fnInterceptor := newFieldNameAggInterceptor(
testNamespace,
searchattribute.TestNameTypeMap,
searchattribute.NewTestMapperProvider(nil),
)
_, err := fnInterceptor.Name("CustomIntField", query.FieldNameFilter)
s.NoError(err)
s.Equal(map[string]bool{"CustomIntField": true}, fnInterceptor.names)
_, err = fnInterceptor.Name("CustomKeywordField", query.FieldNameFilter)
s.NoError(err)
s.Equal(map[string]bool{"CustomIntField": true, "CustomKeywordField": true}, fnInterceptor.names)
_, err = fnInterceptor.Name("CustomIntField", query.FieldNameFilter)
s.NoError(err)
s.Equal(map[string]bool{"CustomIntField": true, "CustomKeywordField": true}, fnInterceptor.names)
_, err = fnInterceptor.Name("search-attribute-not-found", query.FieldNameFilter)
s.Error(err)
}
func TestGetQueryFields(t *testing.T) {
testCases := []struct {
name string
input string
expectedFields []string
expectedErrMsg string
}{
{
name: "empty query string",
input: "",
expectedFields: []string{},
expectedErrMsg: "",
},
{
name: "filter custom search attribute",
input: "CustomKeywordField = 'foo'",
expectedFields: []string{"CustomKeywordField"},
expectedErrMsg: "",
},
{
name: "filter multiple custom search attribute",
input: "(CustomKeywordField = 'foo' AND CustomIntField = 123) OR CustomKeywordField = 'bar'",
expectedFields: []string{"CustomKeywordField", "CustomIntField"},
expectedErrMsg: "",
},
{
name: "filter TemporalSchedulePaused",
input: "TemporalSchedulePaused = true",
expectedFields: []string{"TemporalSchedulePaused"},
expectedErrMsg: "",
},
{
name: "filter TemporalSchedulePaused",
input: "TemporalSchedulePaused = true",
expectedFields: []string{"TemporalSchedulePaused"},
expectedErrMsg: "",
},
{
name: "filter TemporalSchedulePaused and custom search attribute",
input: "TemporalSchedulePaused = true AND CustomKeywordField = 'foo'",
expectedFields: []string{"TemporalSchedulePaused", "CustomKeywordField"},
expectedErrMsg: "",
},
{
name: "filter system search attribute",
input: "ExecutionDuration > '1s'",
expectedFields: []string{"ExecutionDuration"},
expectedErrMsg: "",
},
{
name: "invalid query filter",
input: "CustomKeywordField = foo",
expectedFields: nil,
expectedErrMsg: "invalid query",
},
{
name: "invalid custom search attribute",
input: "Foo = 'bar'",
expectedFields: nil,
expectedErrMsg: "invalid search attribute: Foo",
},
}
for _, tc := range testCases {
t.Run(
tc.name,
func(t *testing.T) {
s := require.New(t)
fields, err := getQueryFields(
testNamespace,
searchattribute.TestNameTypeMap,
searchattribute.NewTestMapperProvider(nil),
tc.input,
)
if tc.expectedErrMsg == "" {
s.NoError(err)
s.Equal(len(tc.expectedFields), len(fields))
for _, f := range fields {
s.Contains(tc.expectedFields, f)
}
} else {
var invalidArgErr *serviceerror.InvalidArgument
s.ErrorAs(err, &invalidArgErr)
s.ErrorContains(err, tc.expectedErrMsg)
}
},
)
}
}
func TestValidateVisibilityQuery(t *testing.T) {
testCases := []struct {
name string
input string
expectedErrMsg string
}{
{
name: "empty query string",
input: "",
expectedErrMsg: "",
},
{
name: "filter custom search attribute",
input: "CustomKeywordField = 'foo'",
expectedErrMsg: "",
},
{
name: "filter multiple custom search attribute",
input: "(CustomKeywordField = 'foo' AND CustomIntField = 123) OR CustomKeywordField = 'bar'",
expectedErrMsg: "",
},
{
name: "filter TemporalSchedulePaused",
input: "TemporalSchedulePaused = true",
expectedErrMsg: "",
},
{
name: "filter TemporalSchedulePaused",
input: "TemporalSchedulePaused = true",
expectedErrMsg: "",
},
{
name: "filter TemporalSchedulePaused and custom search attribute",
input: "TemporalSchedulePaused = true AND CustomKeywordField = 'foo'",
expectedErrMsg: "",
},
{
name: "invalid filter system search attribute",
input: "ExecutionDuration > '1s'",
expectedErrMsg: "invalid query filter for schedules: cannot filter on \"ExecutionDuration\"",
},
{
name: "invalid query filter",
input: "CustomKeywordField = foo",
expectedErrMsg: "invalid query",
},
{
name: "invalid custom search attribute",
input: "Foo = foo",
expectedErrMsg: "invalid search attribute: Foo",
},
}
for _, tc := range testCases {
t.Run(
tc.name,
func(t *testing.T) {
s := require.New(t)
err := ValidateVisibilityQuery(
testNamespace,
searchattribute.TestNameTypeMap,
searchattribute.NewTestMapperProvider(nil),
tc.input,
)
if tc.expectedErrMsg == "" {
s.NoError(err)
} else {
var invalidArgErr *serviceerror.InvalidArgument
s.ErrorAs(err, &invalidArgErr)
s.ErrorContains(err, tc.expectedErrMsg)
}
},
)
}
}