| 1 | package extension |
| 2 | |
| 3 | import ( |
| 4 | "testing" |
| 5 | |
| 6 | "reasonix/internal/extensioncontract" |
| 7 | ) |
| 8 | |
| 9 | func TestClassifySubgraphNone(t *testing.T) { |
| 10 | g, err := BuildDependencyGraph([]ComponentDescriptor{ |
| 11 | {ID: "host", Provides: []extensioncontract.Capability{cap("reasonix", "provider", "p", "1.0.0", "sha256:p")}}, |
| 12 | }) |
| 13 | if err != nil { |
| 14 | t.Fatal(err) |
| 15 | } |
| 16 | plan := DiffRuntimePlan(g, g, 1, 2) |
| 17 | if plan.Kind != SubgraphNone || plan.MayChangePrefix() { |
| 18 | t.Fatalf("kind=%v mayChangePrefix=%v", plan.Kind, plan.MayChangePrefix()) |
| 19 | } |
| 20 | } |
| 21 | |
| 22 | func TestClassifySubgraphInterceptorOnly(t *testing.T) { |
| 23 | from, _ := BuildDependencyGraph([]ComponentDescriptor{ |
| 24 | {ID: "plugin/a", Intercepts: []InterceptorPoint{PointToolBefore}}, |
| 25 | }) |
| 26 | to, _ := BuildDependencyGraph([]ComponentDescriptor{ |
| 27 | {ID: "plugin/a", Intercepts: []InterceptorPoint{PointToolBefore, PointToolAfter}, |
| 28 | Provides: []extensioncontract.Capability{{ |
| 29 | Key: extensioncontract.CapabilityKey{Namespace: "plugin/a", Kind: "interceptors", ID: "default"}, Version: "1.0.0", |
| 30 | }}}, |
| 31 | }) |
| 32 | plan := DiffRuntimePlan(from, to, 1, 2) |
| 33 | if plan.Kind != SubgraphInterceptorOnly { |
| 34 | t.Fatalf("kind = %v, want interceptor-only", plan.Kind) |
| 35 | } |
| 36 | if plan.MayChangePrefix() { |
| 37 | t.Fatal("interceptor-only must not affect cache") |
| 38 | } |
| 39 | if !plan.AffectsInterceptors() { |
| 40 | t.Fatal("expected AffectsInterceptors") |
| 41 | } |
| 42 | } |
| 43 | |
| 44 | func TestClassifySubgraphProviderOnly(t *testing.T) { |
| 45 | from, _ := BuildDependencyGraph([]ComponentDescriptor{ |
| 46 | {ID: "plugin/p", Provides: []extensioncontract.Capability{cap("plugin/p", "provider", "x", "1.0.0", "sha256:a")}}, |
| 47 | }) |
| 48 | to, _ := BuildDependencyGraph([]ComponentDescriptor{ |
| 49 | {ID: "plugin/p", Provides: []extensioncontract.Capability{cap("plugin/p", "provider", "x", "1.1.0", "sha256:b")}}, |
| 50 | }) |
| 51 | plan := DiffRuntimePlan(from, to, 1, 2) |
| 52 | if plan.Kind != SubgraphProviderOnly { |
| 53 | t.Fatalf("kind = %v, want provider-only", plan.Kind) |
| 54 | } |
| 55 | if !plan.AffectsProviders() || !plan.MayChangePrefix() { |
| 56 | t.Fatal("provider-only should affect providers and conservatively check the prefix") |
| 57 | } |
| 58 | if !plan.ProviderChanged || plan.PrefixChanged { |
| 59 | t.Fatalf("provider-only observation flags = provider:%v prefix:%v", plan.ProviderChanged, plan.PrefixChanged) |
| 60 | } |
| 61 | } |
| 62 |