@@ -22,9 +22,11 @@ import (
22
22
"github.com/solo-io/gloo/pkg/utils/statusutils"
23
23
sologatewayv1 "github.com/solo-io/gloo/projects/gateway/pkg/api/v1"
24
24
solokubev1 "github.com/solo-io/gloo/projects/gateway/pkg/api/v1/kube/apis/gateway.solo.io/v1"
25
+ "github.com/solo-io/gloo/projects/gateway2/query"
25
26
gwquery "github.com/solo-io/gloo/projects/gateway2/query"
26
27
"github.com/solo-io/gloo/projects/gateway2/reports"
27
28
. "github.com/solo-io/gloo/projects/gateway2/translator"
29
+ "github.com/solo-io/gloo/projects/gateway2/translator/plugins"
28
30
httplisquery "github.com/solo-io/gloo/projects/gateway2/translator/plugins/httplisteneroptions/query"
29
31
lisquery "github.com/solo-io/gloo/projects/gateway2/translator/plugins/listeneroptions/query"
30
32
"github.com/solo-io/gloo/projects/gateway2/translator/plugins/registry"
@@ -52,6 +54,36 @@ func CompareProxy(expectedFile string, actualProxy *v1.Proxy) (string, error) {
52
54
return cmp .Diff (expectedProxy , actualProxy , protocmp .Transform (), cmpopts .EquateNaNs ()), nil
53
55
}
54
56
57
+ var (
58
+ _ plugins.BackendPlugin = & testBackendPlugin {}
59
+ _ query.BackendRefResolver = & testBackendPlugin {}
60
+ )
61
+
62
+ type testBackendPlugin struct {}
63
+
64
+ // GetBackendForRef implements query.BackendRefResolver.
65
+ func (tp * testBackendPlugin ) GetBackendForRef (ctx context.Context , obj gwquery.From , ref * gwv1.BackendObjectReference ) (client.Object , error , bool ) {
66
+ if ref .Kind == nil || * ref .Kind != "test-backend-plugin" {
67
+ return nil , nil , false
68
+ }
69
+ // doesn't matter as long as its not nil
70
+ return & gwv1.HTTPRoute {}, nil , true
71
+ }
72
+
73
+ func (tp * testBackendPlugin ) ApplyBackendPlugin (
74
+ resolvedBackend client.Object ,
75
+ ref gwv1.BackendObjectReference ,
76
+ ) (* v1.Destination , bool ) {
77
+ if ref .Kind == nil || * ref .Kind != "test-backend-plugin" {
78
+ return nil , false
79
+ }
80
+ return & v1.Destination {
81
+ DestinationType : & v1.Destination_Upstream {
82
+ Upstream : & core.ResourceRef {Name : "test-backend-plugin-us" },
83
+ },
84
+ }, true
85
+ }
86
+
55
87
func (tc TestCase ) Run (ctx context.Context ) (map [types.NamespacedName ]ActualTestResult , error ) {
56
88
var (
57
89
gateways []* gwv1.Gateway
@@ -94,7 +126,7 @@ func (tc TestCase) Run(ctx context.Context) (map[types.NamespacedName]ActualTest
94
126
lisquery .IterateIndices ,
95
127
httplisquery .IterateIndices ,
96
128
)
97
- queries := testutils .BuildGatewayQueriesWithClient (fakeClient )
129
+ queries := testutils .BuildGatewayQueriesWithClient (fakeClient , query . WithBackendRefResolvers ( & testBackendPlugin {}) )
98
130
99
131
resourceClientFactory := & factory.MemoryResourceClientFactory {
100
132
Cache : memory .NewInMemoryResourceCache (),
@@ -109,7 +141,9 @@ func (tc TestCase) Run(ctx context.Context) (map[types.NamespacedName]ActualTest
109
141
routeOptionCollection := krt .NewStaticCollection (routeOptions )
110
142
vhOptionCollection := krt .NewStatic [* solokubev1.VirtualHostOption ](nil , true ).AsCollection ()
111
143
112
- pluginRegistry := registry .NewPluginRegistry (registry .BuildPlugins (queries , fakeClient , routeOptionCollection , vhOptionCollection , statusReporter ))
144
+ allPlugins := registry .BuildPlugins (queries , fakeClient , routeOptionCollection , vhOptionCollection , statusReporter )
145
+ allPlugins = append (allPlugins , & testBackendPlugin {})
146
+ pluginRegistry := registry .NewPluginRegistry (allPlugins )
113
147
114
148
results := make (map [types.NamespacedName ]ActualTestResult )
115
149
0 commit comments