Skip to content

SigNoz is an open-source, OpenTelemetry-native observability platform for your team and their AI agents. Get logs, metrics, and traces in one tool with features like APM, distributed tracing, log management, infra monitoring, etc. Combined with SigNoz MCP and a native AI teammate (in SigNoz Cloud) it helps you build more resilient apps.

927 B
Raw Blame
package signozapiserver

import (
	"encoding/json"
	"testing"

	"github.com/SigNoz/signoz/pkg/types/ruletypes"
)

// TestPostableRuleExamplesValidate verifies every example payload returned by
// postableRuleExamples() round-trips through PostableRule.UnmarshalJSON and
// passes Validate(). If an example drifts from the runtime contract this
// breaks loudly so the spec doesn't ship invalid payloads to users.
func TestPostableRuleExamplesValidate(t *testing.T) {
	for _, example := range postableRuleExamples() {
		t.Run(example.Name, func(t *testing.T) {
			raw, err := json.Marshal(example.Value)
			if err != nil {
				t.Fatalf("marshal example: %v", err)
			}

			var rule ruletypes.PostableRule
			if err := json.Unmarshal(raw, &rule); err != nil {
				t.Fatalf("unmarshal: %v\npayload: %s", err, raw)
			}

			if err := rule.Validate(); err != nil {
				t.Fatalf("Validate: %v\npayload: %s", err, raw)
			}
		})
	}
}