Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 30 additions & 3 deletions router-tests/router_oci_plugin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"go.uber.org/zap/zaptest/observer"

"github.com/wundergraph/cosmo/router-tests/testenv"
nodev1 "github.com/wundergraph/cosmo/router/gen/proto/wg/cosmo/node/v1"
)

func TestOCIPlugin_PullAndRun(t *testing.T) {
Expand All @@ -28,7 +29,8 @@ func TestOCIPlugin_PullAndRun(t *testing.T) {
buildAndPushPluginImage(t, registryHost, "test-org/courses", "v1", coursesBinary)

testenv.Run(t, &testenv.Config{
RouterConfigJSONTemplate: testenv.ConfigWithOCIPluginsJSONTemplate,
RouterConfigJSONTemplate: testenv.ConfigWithPluginsJSONTemplate,
ModifyRouterConfig: addOCIImageReferences,
Plugins: testenv.PluginConfig{
Enabled: true,
RegistryURL: registryHost,
Expand All @@ -53,7 +55,8 @@ func TestOCIPlugin_ImageNotFound(t *testing.T) {
// Don't push any images — registry is empty

testenv.FailsOnStartup(t, &testenv.Config{
RouterConfigJSONTemplate: testenv.ConfigWithOCIPluginsJSONTemplate,
RouterConfigJSONTemplate: testenv.ConfigWithPluginsJSONTemplate,
ModifyRouterConfig: addOCIImageReferences,
Plugins: testenv.PluginConfig{
Enabled: true,
RegistryURL: registryHost,
Expand All @@ -75,7 +78,8 @@ func TestOCIPlugin_Restart(t *testing.T) {
buildAndPushPluginImage(t, registryHost, "test-org/courses", "v1", coursesBinary)

testenv.Run(t, &testenv.Config{
RouterConfigJSONTemplate: testenv.ConfigWithOCIPluginsJSONTemplate,
RouterConfigJSONTemplate: testenv.ConfigWithPluginsJSONTemplate,
ModifyRouterConfig: addOCIImageReferences,
LogObservation: testenv.LogObservationConfig{
Enabled: true,
LogLevel: zapcore.ErrorLevel,
Expand Down Expand Up @@ -106,3 +110,26 @@ func TestOCIPlugin_Restart(t *testing.T) {
}, 20*time.Second, 2*time.Second)
})
}

// addOCIImageReferences adds imageReference fields to plugin datasources,
// deriving the OCI config from the base plugins config at runtime.
func addOCIImageReferences(routerConfig *nodev1.RouterConfig) {
for _, ds := range routerConfig.EngineConfig.DatasourceConfigurations {
plugin := ds.GetCustomGraphql().GetGrpc().GetPlugin()
if plugin == nil {
continue
}
switch plugin.Name {
case "projects":
plugin.ImageReference = &nodev1.ImageReference{
Repository: "test-org/projects",
Reference: "v1",
}
case "courses":
plugin.ImageReference = &nodev1.ImageReference{
Repository: "test-org/courses",
Reference: "v1",
}
}
}
}
Loading
Loading