MCPcopy Index your code
hub / github.com/cortexproject/cortex / TestRuler_Create

Function TestRuler_Create

pkg/ruler/api_test.go:460–561  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

458}
459
460func TestRuler_Create(t *testing.T) {
461 store := newMockRuleStore(make(map[string]rulespb.RuleGroupList), nil)
462 cfg := defaultRulerConfig(t)
463
464 r := newTestRuler(t, cfg, store, nil)
465 defer services.StopAndAwaitTerminated(context.Background(), r) //nolint:errcheck
466
467 a := NewAPI(r, r.store, log.NewNopLogger())
468
469 tc := []struct {
470 name string
471 input string
472 output string
473 err error
474 status int
475 }{
476 {
477 name: "with an empty payload",
478 input: "",
479 status: 400,
480 err: errors.New("invalid rules config: rule group name must not be empty"),
481 },
482 {
483 name: "with no rule group name",
484 input: `
485interval: 15s
486rules:
487- record: up_rule
488 expr: up
489`,
490 status: 400,
491 err: errors.New("invalid rules config: rule group name must not be empty"),
492 },
493 {
494 name: "with no rules",
495 input: `
496name: rg_name
497interval: 15s
498`,
499 status: 400,
500 err: errors.New("invalid rules config: rule group 'rg_name' has no rules"),
501 },
502 {
503 name: "with a valid rules file",
504 status: 202,
505 input: `
506name: test
507interval: 15s
508rules:
509- record: up_rule
510 expr: up{}
511- alert: up_alert
512 expr: sum(up{}) > 1
513 for: 30s
514 annotations:
515 test: test
516 labels:
517 test: test

Callers

nothing calls this directly

Calls 11

StopAndAwaitTerminatedFunction · 0.92
newMockRuleStoreFunction · 0.85
defaultRulerConfigFunction · 0.85
newTestRulerFunction · 0.85
requestForFunction · 0.85
NewAPIFunction · 0.70
RunMethod · 0.65
EqualMethod · 0.65
StringMethod · 0.65
ServeHTTPMethod · 0.45
ErrorMethod · 0.45

Tested by

no test coverage detected