From 4124828c00c02626eb8d165e131475b1fa696d1f Mon Sep 17 00:00:00 2001 From: Tobias Guggenmos Date: Fri, 21 Feb 2020 12:43:30 +0100 Subject: [PATCH] Add test to check that promql.FunctionCalls and parser.Functions contain the same functions Signed-off-by: Tobias Guggenmos --- promql/functions_test.go | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/promql/functions_test.go b/promql/functions_test.go index a6aa1cc13..b065768e0 100644 --- a/promql/functions_test.go +++ b/promql/functions_test.go @@ -15,11 +15,13 @@ package promql import ( "context" + "fmt" "testing" "time" "github.com/prometheus/prometheus/pkg/labels" "github.com/prometheus/prometheus/pkg/timestamp" + "github.com/prometheus/prometheus/promql/parser" "github.com/prometheus/prometheus/util/teststorage" "github.com/prometheus/prometheus/util/testutil" ) @@ -56,3 +58,24 @@ func TestDeriv(t *testing.T) { testutil.Assert(t, len(vec) == 1, "Expected 1 result, got %d", len(vec)) testutil.Assert(t, vec[0].V == 0.0, "Expected 0.0 as value, got %f", vec[0].V) } + +func TestFunctionList(t *testing.T) { + // Test that Functions and parser.Functions list the same functions + for i := range FunctionCalls { + _, ok := parser.Functions[i] + + if !ok { + panic(fmt.Sprintf("function %s exists in promql package, but not in parser package", i)) + } + + } + + for i := range parser.Functions { + _, ok := FunctionCalls[i] + + if !ok { + panic(fmt.Sprintf("function %s exists in promql package, but not in parser package", i)) + } + + } +}