MCPcopy Create free account
hub / github.com/conforma/cli / TestPolicySourcesFrom

Function TestPolicySourcesFrom

internal/policy/source/source_test.go:415–513  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

413}
414
415func TestPolicySourcesFrom(t *testing.T) {
416 tests := []struct {
417 name string
418 source ecc.Source
419 expected []PolicySource
420 expectedCount int
421 }{
422 {
423 name: "fetches policy and data configs",
424 source: ecc.Source{
425 Name: "policy1",
426 Policy: []string{"github.com/org/repo1//policy/", "github.com/org/repo2//policy/", "github.com/org/repo3//policy/"},
427 Data: []string{"github.com/org/repo1//data/", "github.com/org/repo2//data/", "github.com/org/repo3//data/"},
428 },
429 expected: []PolicySource{
430 &PolicyUrl{Url: "github.com/org/repo1//policy/", Kind: PolicyKind},
431 &PolicyUrl{Url: "github.com/org/repo2//policy/", Kind: PolicyKind},
432 &PolicyUrl{Url: "github.com/org/repo3//policy/", Kind: PolicyKind},
433 &PolicyUrl{Url: "github.com/org/repo1//data/", Kind: DataKind},
434 &PolicyUrl{Url: "github.com/org/repo2//data/", Kind: DataKind},
435 &PolicyUrl{Url: "github.com/org/repo3//data/", Kind: DataKind},
436 },
437 expectedCount: 6,
438 },
439 {
440 name: "handles rule data with policy and data",
441 source: ecc.Source{
442 Name: "policy2",
443 Policy: []string{"github.com/org/repo1//policy/"},
444 Data: []string{"github.com/org/repo1//data/"},
445 RuleData: &extv1.JSON{Raw: []byte(`"foo":"bar"`)},
446 },
447 expected: []PolicySource{
448 &PolicyUrl{Url: "github.com/org/repo1//policy/", Kind: PolicyKind},
449 &PolicyUrl{Url: "github.com/org/repo1//data/", Kind: DataKind},
450 inlineData{source: []byte("{\"rule_data__configuration__\":\"foo\":\"bar\"}")},
451 },
452 expectedCount: 3,
453 },
454 {
455 name: "empty source returns empty slice",
456 source: ecc.Source{
457 Name: "empty",
458 },
459 expected: []PolicySource{},
460 expectedCount: 0,
461 },
462 {
463 name: "only rule data without policy or data sources",
464 source: ecc.Source{
465 Name: "rule-data-only",
466 RuleData: &extv1.JSON{Raw: []byte(`{"setting": "value"}`)},
467 },
468 expected: []PolicySource{
469 inlineData{source: []byte("{\"rule_data__configuration__\":{\"setting\": \"value\"}}")},
470 },
471 expectedCount: 1,
472 },

Callers

nothing calls this directly

Calls 4

PolicySourcesFromFunction · 0.85
RunMethod · 0.65
TypeMethod · 0.65
SubdirMethod · 0.65

Tested by

no test coverage detected