|
|
@ -60,6 +60,7 @@ func TestMain(m *testing.M) { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func TestQueryRange(t *testing.T) { |
|
|
|
func TestQueryRange(t *testing.T) { |
|
|
|
|
|
|
|
t.Parallel() |
|
|
|
s, getRequest := mockServer(200, `{"status": "success", "data": {"resultType": "matrix", "result": []}}`) |
|
|
|
s, getRequest := mockServer(200, `{"status": "success", "data": {"resultType": "matrix", "result": []}}`) |
|
|
|
defer s.Close() |
|
|
|
defer s.Close() |
|
|
|
|
|
|
|
|
|
|
@ -83,6 +84,7 @@ func TestQueryRange(t *testing.T) { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func TestQueryInstant(t *testing.T) { |
|
|
|
func TestQueryInstant(t *testing.T) { |
|
|
|
|
|
|
|
t.Parallel() |
|
|
|
s, getRequest := mockServer(200, `{"status": "success", "data": {"resultType": "vector", "result": []}}`) |
|
|
|
s, getRequest := mockServer(200, `{"status": "success", "data": {"resultType": "vector", "result": []}}`) |
|
|
|
defer s.Close() |
|
|
|
defer s.Close() |
|
|
|
|
|
|
|
|
|
|
@ -114,6 +116,7 @@ func mockServer(code int, body string) (*httptest.Server, func() *http.Request) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func TestCheckSDFile(t *testing.T) { |
|
|
|
func TestCheckSDFile(t *testing.T) { |
|
|
|
|
|
|
|
t.Parallel() |
|
|
|
cases := []struct { |
|
|
|
cases := []struct { |
|
|
|
name string |
|
|
|
name string |
|
|
|
file string |
|
|
|
file string |
|
|
@ -144,6 +147,7 @@ func TestCheckSDFile(t *testing.T) { |
|
|
|
} |
|
|
|
} |
|
|
|
for _, test := range cases { |
|
|
|
for _, test := range cases { |
|
|
|
t.Run(test.name, func(t *testing.T) { |
|
|
|
t.Run(test.name, func(t *testing.T) { |
|
|
|
|
|
|
|
t.Parallel() |
|
|
|
_, err := checkSDFile(test.file) |
|
|
|
_, err := checkSDFile(test.file) |
|
|
|
if test.err != "" { |
|
|
|
if test.err != "" { |
|
|
|
require.EqualErrorf(t, err, test.err, "Expected error %q, got %q", test.err, err.Error()) |
|
|
|
require.EqualErrorf(t, err, test.err, "Expected error %q, got %q", test.err, err.Error()) |
|
|
@ -155,6 +159,7 @@ func TestCheckSDFile(t *testing.T) { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func TestCheckDuplicates(t *testing.T) { |
|
|
|
func TestCheckDuplicates(t *testing.T) { |
|
|
|
|
|
|
|
t.Parallel() |
|
|
|
cases := []struct { |
|
|
|
cases := []struct { |
|
|
|
name string |
|
|
|
name string |
|
|
|
ruleFile string |
|
|
|
ruleFile string |
|
|
@ -179,6 +184,7 @@ func TestCheckDuplicates(t *testing.T) { |
|
|
|
for _, test := range cases { |
|
|
|
for _, test := range cases { |
|
|
|
c := test |
|
|
|
c := test |
|
|
|
t.Run(c.name, func(t *testing.T) { |
|
|
|
t.Run(c.name, func(t *testing.T) { |
|
|
|
|
|
|
|
t.Parallel() |
|
|
|
rgs, err := rulefmt.ParseFile(c.ruleFile) |
|
|
|
rgs, err := rulefmt.ParseFile(c.ruleFile) |
|
|
|
require.Empty(t, err) |
|
|
|
require.Empty(t, err) |
|
|
|
dups := checkDuplicates(rgs.Groups) |
|
|
|
dups := checkDuplicates(rgs.Groups) |
|
|
@ -198,6 +204,7 @@ func BenchmarkCheckDuplicates(b *testing.B) { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func TestCheckTargetConfig(t *testing.T) { |
|
|
|
func TestCheckTargetConfig(t *testing.T) { |
|
|
|
|
|
|
|
t.Parallel() |
|
|
|
cases := []struct { |
|
|
|
cases := []struct { |
|
|
|
name string |
|
|
|
name string |
|
|
|
file string |
|
|
|
file string |
|
|
@ -226,6 +233,7 @@ func TestCheckTargetConfig(t *testing.T) { |
|
|
|
} |
|
|
|
} |
|
|
|
for _, test := range cases { |
|
|
|
for _, test := range cases { |
|
|
|
t.Run(test.name, func(t *testing.T) { |
|
|
|
t.Run(test.name, func(t *testing.T) { |
|
|
|
|
|
|
|
t.Parallel() |
|
|
|
_, err := checkConfig(false, "testdata/"+test.file, false) |
|
|
|
_, err := checkConfig(false, "testdata/"+test.file, false) |
|
|
|
if test.err != "" { |
|
|
|
if test.err != "" { |
|
|
|
require.EqualErrorf(t, err, test.err, "Expected error %q, got %q", test.err, err.Error()) |
|
|
|
require.EqualErrorf(t, err, test.err, "Expected error %q, got %q", test.err, err.Error()) |
|
|
@ -237,6 +245,7 @@ func TestCheckTargetConfig(t *testing.T) { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func TestCheckConfigSyntax(t *testing.T) { |
|
|
|
func TestCheckConfigSyntax(t *testing.T) { |
|
|
|
|
|
|
|
t.Parallel() |
|
|
|
cases := []struct { |
|
|
|
cases := []struct { |
|
|
|
name string |
|
|
|
name string |
|
|
|
file string |
|
|
|
file string |
|
|
@ -309,6 +318,7 @@ func TestCheckConfigSyntax(t *testing.T) { |
|
|
|
} |
|
|
|
} |
|
|
|
for _, test := range cases { |
|
|
|
for _, test := range cases { |
|
|
|
t.Run(test.name, func(t *testing.T) { |
|
|
|
t.Run(test.name, func(t *testing.T) { |
|
|
|
|
|
|
|
t.Parallel() |
|
|
|
_, err := checkConfig(false, "testdata/"+test.file, test.syntaxOnly) |
|
|
|
_, err := checkConfig(false, "testdata/"+test.file, test.syntaxOnly) |
|
|
|
expectedErrMsg := test.err |
|
|
|
expectedErrMsg := test.err |
|
|
|
if strings.Contains(runtime.GOOS, "windows") { |
|
|
|
if strings.Contains(runtime.GOOS, "windows") { |
|
|
@ -324,6 +334,7 @@ func TestCheckConfigSyntax(t *testing.T) { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func TestAuthorizationConfig(t *testing.T) { |
|
|
|
func TestAuthorizationConfig(t *testing.T) { |
|
|
|
|
|
|
|
t.Parallel() |
|
|
|
cases := []struct { |
|
|
|
cases := []struct { |
|
|
|
name string |
|
|
|
name string |
|
|
|
file string |
|
|
|
file string |
|
|
@ -343,6 +354,7 @@ func TestAuthorizationConfig(t *testing.T) { |
|
|
|
|
|
|
|
|
|
|
|
for _, test := range cases { |
|
|
|
for _, test := range cases { |
|
|
|
t.Run(test.name, func(t *testing.T) { |
|
|
|
t.Run(test.name, func(t *testing.T) { |
|
|
|
|
|
|
|
t.Parallel() |
|
|
|
_, err := checkConfig(false, "testdata/"+test.file, false) |
|
|
|
_, err := checkConfig(false, "testdata/"+test.file, false) |
|
|
|
if test.err != "" { |
|
|
|
if test.err != "" { |
|
|
|
require.ErrorContains(t, err, test.err, "Expected error to contain %q, got %q", test.err, err.Error()) |
|
|
|
require.ErrorContains(t, err, test.err, "Expected error to contain %q, got %q", test.err, err.Error()) |
|
|
@ -357,6 +369,7 @@ func TestCheckMetricsExtended(t *testing.T) { |
|
|
|
if runtime.GOOS == "windows" { |
|
|
|
if runtime.GOOS == "windows" { |
|
|
|
t.Skip("Skipping on windows") |
|
|
|
t.Skip("Skipping on windows") |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
t.Parallel() |
|
|
|
|
|
|
|
|
|
|
|
f, err := os.Open("testdata/metrics-test.prom") |
|
|
|
f, err := os.Open("testdata/metrics-test.prom") |
|
|
|
require.NoError(t, err) |
|
|
|
require.NoError(t, err) |
|
|
@ -393,6 +406,7 @@ func TestExitCodes(t *testing.T) { |
|
|
|
if testing.Short() { |
|
|
|
if testing.Short() { |
|
|
|
t.Skip("skipping test in short mode.") |
|
|
|
t.Skip("skipping test in short mode.") |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
t.Parallel() |
|
|
|
|
|
|
|
|
|
|
|
for _, c := range []struct { |
|
|
|
for _, c := range []struct { |
|
|
|
file string |
|
|
|
file string |
|
|
@ -417,8 +431,10 @@ func TestExitCodes(t *testing.T) { |
|
|
|
}, |
|
|
|
}, |
|
|
|
} { |
|
|
|
} { |
|
|
|
t.Run(c.file, func(t *testing.T) { |
|
|
|
t.Run(c.file, func(t *testing.T) { |
|
|
|
|
|
|
|
t.Parallel() |
|
|
|
for _, lintFatal := range []bool{true, false} { |
|
|
|
for _, lintFatal := range []bool{true, false} { |
|
|
|
t.Run(strconv.FormatBool(lintFatal), func(t *testing.T) { |
|
|
|
t.Run(strconv.FormatBool(lintFatal), func(t *testing.T) { |
|
|
|
|
|
|
|
t.Parallel() |
|
|
|
args := []string{"-test.main", "check", "config", "testdata/" + c.file} |
|
|
|
args := []string{"-test.main", "check", "config", "testdata/" + c.file} |
|
|
|
if lintFatal { |
|
|
|
if lintFatal { |
|
|
|
args = append(args, "--lint-fatal") |
|
|
|
args = append(args, "--lint-fatal") |
|
|
@ -449,6 +465,7 @@ func TestDocumentation(t *testing.T) { |
|
|
|
if runtime.GOOS == "windows" { |
|
|
|
if runtime.GOOS == "windows" { |
|
|
|
t.SkipNow() |
|
|
|
t.SkipNow() |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
t.Parallel() |
|
|
|
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) |
|
|
|
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) |
|
|
|
defer cancel() |
|
|
|
defer cancel() |
|
|
|
|
|
|
|
|
|
|
@ -542,16 +559,19 @@ func TestCheckRules(t *testing.T) { |
|
|
|
|
|
|
|
|
|
|
|
func TestCheckRulesWithRuleFiles(t *testing.T) { |
|
|
|
func TestCheckRulesWithRuleFiles(t *testing.T) { |
|
|
|
t.Run("rules-good", func(t *testing.T) { |
|
|
|
t.Run("rules-good", func(t *testing.T) { |
|
|
|
|
|
|
|
t.Parallel() |
|
|
|
exitCode := CheckRules(newLintConfig(lintOptionDuplicateRules, false), "./testdata/rules.yml") |
|
|
|
exitCode := CheckRules(newLintConfig(lintOptionDuplicateRules, false), "./testdata/rules.yml") |
|
|
|
require.Equal(t, successExitCode, exitCode, "") |
|
|
|
require.Equal(t, successExitCode, exitCode, "") |
|
|
|
}) |
|
|
|
}) |
|
|
|
|
|
|
|
|
|
|
|
t.Run("rules-bad", func(t *testing.T) { |
|
|
|
t.Run("rules-bad", func(t *testing.T) { |
|
|
|
|
|
|
|
t.Parallel() |
|
|
|
exitCode := CheckRules(newLintConfig(lintOptionDuplicateRules, false), "./testdata/rules-bad.yml") |
|
|
|
exitCode := CheckRules(newLintConfig(lintOptionDuplicateRules, false), "./testdata/rules-bad.yml") |
|
|
|
require.Equal(t, failureExitCode, exitCode, "") |
|
|
|
require.Equal(t, failureExitCode, exitCode, "") |
|
|
|
}) |
|
|
|
}) |
|
|
|
|
|
|
|
|
|
|
|
t.Run("rules-lint-fatal", func(t *testing.T) { |
|
|
|
t.Run("rules-lint-fatal", func(t *testing.T) { |
|
|
|
|
|
|
|
t.Parallel() |
|
|
|
exitCode := CheckRules(newLintConfig(lintOptionDuplicateRules, true), "./testdata/prometheus-rules.lint.yml") |
|
|
|
exitCode := CheckRules(newLintConfig(lintOptionDuplicateRules, true), "./testdata/prometheus-rules.lint.yml") |
|
|
|
require.Equal(t, lintErrExitCode, exitCode, "") |
|
|
|
require.Equal(t, lintErrExitCode, exitCode, "") |
|
|
|
}) |
|
|
|
}) |
|
|
@ -561,6 +581,7 @@ func TestTSDBDumpCommand(t *testing.T) { |
|
|
|
if testing.Short() { |
|
|
|
if testing.Short() { |
|
|
|
t.Skip("skipping test in short mode.") |
|
|
|
t.Skip("skipping test in short mode.") |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
t.Parallel() |
|
|
|
|
|
|
|
|
|
|
|
storage := promqltest.LoadedStorage(t, ` |
|
|
|
storage := promqltest.LoadedStorage(t, ` |
|
|
|
load 1m |
|
|
|
load 1m |
|
|
@ -593,6 +614,7 @@ func TestTSDBDumpCommand(t *testing.T) { |
|
|
|
}, |
|
|
|
}, |
|
|
|
} { |
|
|
|
} { |
|
|
|
t.Run(c.name, func(t *testing.T) { |
|
|
|
t.Run(c.name, func(t *testing.T) { |
|
|
|
|
|
|
|
t.Parallel() |
|
|
|
args := []string{"-test.main", "tsdb", c.subCmd, storage.Dir()} |
|
|
|
args := []string{"-test.main", "tsdb", c.subCmd, storage.Dir()} |
|
|
|
cmd := exec.Command(promtoolPath, args...) |
|
|
|
cmd := exec.Command(promtoolPath, args...) |
|
|
|
require.NoError(t, cmd.Run()) |
|
|
|
require.NoError(t, cmd.Run()) |
|
|
|