(t *testing.T)
| 1959 | } |
| 1960 | |
| 1961 | func TestParseRewrites(t *testing.T) { |
| 1962 | tests := []struct { |
| 1963 | name string |
| 1964 | query string |
| 1965 | want string |
| 1966 | }{ |
| 1967 | { |
| 1968 | name: "no rewrites", |
| 1969 | query: "{ .attr = `foo` }", |
| 1970 | want: "{ .attr = `foo` }", |
| 1971 | }, |
| 1972 | { |
| 1973 | name: "query with rewrite OR", |
| 1974 | query: "{ .attr = `foo` || .attr = `bar` } | rate()", |
| 1975 | want: "{ .attr IN [`foo`, `bar`] } | rate()", |
| 1976 | }, |
| 1977 | { |
| 1978 | name: "query with rewrite AND", |
| 1979 | query: "{ .attr != `foo` && .attr != `bar` }", |
| 1980 | want: "{ .attr NOT IN [`foo`, `bar`] }", |
| 1981 | }, |
| 1982 | { |
| 1983 | name: "query with rewrite OR regex", |
| 1984 | query: "{ .attr =~ `foo` || .attr =~ `bar` }", |
| 1985 | want: "{ .attr MATCH ANY [`foo`, `bar`] }", |
| 1986 | }, |
| 1987 | { |
| 1988 | name: "query with rewrite AND regex", |
| 1989 | query: "{ .attr !~ `foo` && .attr !~ `bar` }", |
| 1990 | want: "{ .attr MATCH NONE [`foo`, `bar`] }", |
| 1991 | }, |
| 1992 | { |
| 1993 | name: "skip rewrites via unsafe hint", |
| 1994 | query: "{ .attr = `foo` || .attr = `bar` } | rate() with(skip_ast_transformations=`or_to_in`)", |
| 1995 | want: "{ (.attr = `foo`) || (.attr = `bar`) } | rate() with(skip_ast_transformations=`or_to_in`)", |
| 1996 | }, |
| 1997 | } |
| 1998 | |
| 1999 | for _, tc := range tests { |
| 2000 | t.Run(tc.name, func(t *testing.T) { |
| 2001 | actual, err := Parse(tc.query, WithUnsafeHints(true)) |
| 2002 | require.NoError(t, err) |
| 2003 | require.Equal(t, tc.want, actual.String()) |
| 2004 | }) |
| 2005 | } |
| 2006 | } |
| 2007 | |
| 2008 | func TestMetricsFilter(t *testing.T) { |
| 2009 | tests := []struct { |
nothing calls this directly
no test coverage detected