|
7 | 7 | "github.com/stretchr/testify/assert" |
8 | 8 | "github.com/stretchr/testify/require" |
9 | 9 | "github.com/superplanehq/superplane/pkg/core" |
| 10 | + "github.com/superplanehq/superplane/pkg/models" |
10 | 11 | "github.com/superplanehq/superplane/pkg/registry" |
11 | 12 | supportcontexts "github.com/superplanehq/superplane/test/support/contexts" |
12 | 13 | "github.com/superplanehq/superplane/test/support/impl" |
@@ -260,3 +261,207 @@ func TestRegistry_FindIntegrationHook(t *testing.T) { |
260 | 261 | assert.Contains(t, err.Error(), "hook missing-hook not found for integration unit_integration") |
261 | 262 | }) |
262 | 263 | } |
| 264 | + |
| 265 | +func TestRegistry_FindConfigurableComponent(t *testing.T) { |
| 266 | + t.Run("finds action", func(t *testing.T) { |
| 267 | + action := impl.NewDummyAction(impl.DummyActionOptions{Name: "unit_action"}) |
| 268 | + |
| 269 | + r := ®istry.Registry{ |
| 270 | + Actions: map[string]core.Action{"unit_action": registry.NewPanicableAction(action)}, |
| 271 | + Triggers: map[string]core.Trigger{}, |
| 272 | + Integrations: map[string]core.Integration{}, |
| 273 | + Widgets: map[string]core.Widget{}, |
| 274 | + } |
| 275 | + |
| 276 | + component, err := r.FindConfigurableComponent("unit_action") |
| 277 | + require.NoError(t, err) |
| 278 | + |
| 279 | + foundAction, ok := component.(core.Action) |
| 280 | + require.True(t, ok) |
| 281 | + assert.Equal(t, "unit_action", foundAction.Name()) |
| 282 | + }) |
| 283 | + |
| 284 | + t.Run("finds integration action", func(t *testing.T) { |
| 285 | + action := impl.NewDummyAction(impl.DummyActionOptions{Name: "unitapp.action"}) |
| 286 | + integration := impl.NewDummyIntegration(impl.DummyIntegrationOptions{ |
| 287 | + Actions: []core.Action{action}, |
| 288 | + }) |
| 289 | + |
| 290 | + r := ®istry.Registry{ |
| 291 | + Actions: map[string]core.Action{}, |
| 292 | + Triggers: map[string]core.Trigger{}, |
| 293 | + Integrations: map[string]core.Integration{"unitapp": registry.NewPanicableIntegration(integration)}, |
| 294 | + Widgets: map[string]core.Widget{}, |
| 295 | + } |
| 296 | + |
| 297 | + component, err := r.FindConfigurableComponent("unitapp.action") |
| 298 | + require.NoError(t, err) |
| 299 | + |
| 300 | + foundAction, ok := component.(core.Action) |
| 301 | + require.True(t, ok) |
| 302 | + assert.Equal(t, "unitapp.action", foundAction.Name()) |
| 303 | + }) |
| 304 | + |
| 305 | + t.Run("finds trigger", func(t *testing.T) { |
| 306 | + trigger := impl.NewDummyTrigger(impl.DummyTriggerOptions{Name: "unit_trigger"}) |
| 307 | + |
| 308 | + r := ®istry.Registry{ |
| 309 | + Actions: map[string]core.Action{}, |
| 310 | + Triggers: map[string]core.Trigger{"unit_trigger": registry.NewPanicableTrigger(trigger)}, |
| 311 | + Integrations: map[string]core.Integration{}, |
| 312 | + Widgets: map[string]core.Widget{}, |
| 313 | + } |
| 314 | + |
| 315 | + component, err := r.FindConfigurableComponent("unit_trigger") |
| 316 | + require.NoError(t, err) |
| 317 | + |
| 318 | + foundTrigger, ok := component.(core.Trigger) |
| 319 | + require.True(t, ok) |
| 320 | + assert.Equal(t, "unit_trigger", foundTrigger.Name()) |
| 321 | + }) |
| 322 | + |
| 323 | + t.Run("finds widget", func(t *testing.T) { |
| 324 | + widget := impl.NewDummyWidget(impl.DummyWidgetOptions{Name: "unit_widget"}) |
| 325 | + |
| 326 | + r := ®istry.Registry{ |
| 327 | + Actions: map[string]core.Action{}, |
| 328 | + Triggers: map[string]core.Trigger{}, |
| 329 | + Integrations: map[string]core.Integration{}, |
| 330 | + Widgets: map[string]core.Widget{"unit_widget": widget}, |
| 331 | + } |
| 332 | + |
| 333 | + component, err := r.FindConfigurableComponent("unit_widget") |
| 334 | + require.NoError(t, err) |
| 335 | + |
| 336 | + foundWidget, ok := component.(core.Widget) |
| 337 | + require.True(t, ok) |
| 338 | + assert.Equal(t, "unit_widget", foundWidget.Name()) |
| 339 | + }) |
| 340 | + |
| 341 | + t.Run("prefers action when action and trigger share the same name", func(t *testing.T) { |
| 342 | + action := impl.NewDummyAction(impl.DummyActionOptions{Name: "shared_name"}) |
| 343 | + trigger := impl.NewDummyTrigger(impl.DummyTriggerOptions{Name: "shared_name"}) |
| 344 | + |
| 345 | + r := ®istry.Registry{ |
| 346 | + Actions: map[string]core.Action{"shared_name": registry.NewPanicableAction(action)}, |
| 347 | + Triggers: map[string]core.Trigger{"shared_name": registry.NewPanicableTrigger(trigger)}, |
| 348 | + Integrations: map[string]core.Integration{}, |
| 349 | + Widgets: map[string]core.Widget{"shared_name": impl.NewDummyWidget(impl.DummyWidgetOptions{Name: "shared_name"})}, |
| 350 | + } |
| 351 | + |
| 352 | + component, err := r.FindConfigurableComponent("shared_name") |
| 353 | + require.NoError(t, err) |
| 354 | + |
| 355 | + foundAction, ok := component.(core.Action) |
| 356 | + require.True(t, ok) |
| 357 | + assert.Equal(t, "shared_name", foundAction.Name()) |
| 358 | + }) |
| 359 | + |
| 360 | + t.Run("returns error when component is missing", func(t *testing.T) { |
| 361 | + r := ®istry.Registry{ |
| 362 | + Actions: map[string]core.Action{}, |
| 363 | + Triggers: map[string]core.Trigger{}, |
| 364 | + Integrations: map[string]core.Integration{}, |
| 365 | + Widgets: map[string]core.Widget{}, |
| 366 | + } |
| 367 | + |
| 368 | + _, err := r.FindConfigurableComponent("missing_component") |
| 369 | + require.Error(t, err) |
| 370 | + assert.EqualError(t, err, "component missing_component not found") |
| 371 | + }) |
| 372 | +} |
| 373 | + |
| 374 | +func TestRegistry_ComponentType(t *testing.T) { |
| 375 | + t.Run("returns component for action", func(t *testing.T) { |
| 376 | + action := impl.NewDummyAction(impl.DummyActionOptions{Name: "unit_action"}) |
| 377 | + |
| 378 | + r := ®istry.Registry{ |
| 379 | + Actions: map[string]core.Action{"unit_action": registry.NewPanicableAction(action)}, |
| 380 | + Triggers: map[string]core.Trigger{}, |
| 381 | + Integrations: map[string]core.Integration{}, |
| 382 | + Widgets: map[string]core.Widget{}, |
| 383 | + } |
| 384 | + |
| 385 | + componentType, err := r.ComponentType("unit_action") |
| 386 | + require.NoError(t, err) |
| 387 | + assert.Equal(t, models.NodeTypeComponent, componentType) |
| 388 | + }) |
| 389 | + |
| 390 | + t.Run("returns component for integration action", func(t *testing.T) { |
| 391 | + action := impl.NewDummyAction(impl.DummyActionOptions{Name: "unitapp.action"}) |
| 392 | + integration := impl.NewDummyIntegration(impl.DummyIntegrationOptions{ |
| 393 | + Actions: []core.Action{action}, |
| 394 | + }) |
| 395 | + |
| 396 | + r := ®istry.Registry{ |
| 397 | + Actions: map[string]core.Action{}, |
| 398 | + Triggers: map[string]core.Trigger{}, |
| 399 | + Integrations: map[string]core.Integration{"unitapp": registry.NewPanicableIntegration(integration)}, |
| 400 | + Widgets: map[string]core.Widget{}, |
| 401 | + } |
| 402 | + |
| 403 | + componentType, err := r.ComponentType("unitapp.action") |
| 404 | + require.NoError(t, err) |
| 405 | + assert.Equal(t, models.NodeTypeComponent, componentType) |
| 406 | + }) |
| 407 | + |
| 408 | + t.Run("returns trigger for trigger", func(t *testing.T) { |
| 409 | + trigger := impl.NewDummyTrigger(impl.DummyTriggerOptions{Name: "unit_trigger"}) |
| 410 | + |
| 411 | + r := ®istry.Registry{ |
| 412 | + Actions: map[string]core.Action{}, |
| 413 | + Triggers: map[string]core.Trigger{"unit_trigger": registry.NewPanicableTrigger(trigger)}, |
| 414 | + Integrations: map[string]core.Integration{}, |
| 415 | + Widgets: map[string]core.Widget{}, |
| 416 | + } |
| 417 | + |
| 418 | + componentType, err := r.ComponentType("unit_trigger") |
| 419 | + require.NoError(t, err) |
| 420 | + assert.Equal(t, models.NodeTypeTrigger, componentType) |
| 421 | + }) |
| 422 | + |
| 423 | + t.Run("returns widget for widget", func(t *testing.T) { |
| 424 | + widget := impl.NewDummyWidget(impl.DummyWidgetOptions{Name: "unit_widget"}) |
| 425 | + |
| 426 | + r := ®istry.Registry{ |
| 427 | + Actions: map[string]core.Action{}, |
| 428 | + Triggers: map[string]core.Trigger{}, |
| 429 | + Integrations: map[string]core.Integration{}, |
| 430 | + Widgets: map[string]core.Widget{"unit_widget": widget}, |
| 431 | + } |
| 432 | + |
| 433 | + componentType, err := r.ComponentType("unit_widget") |
| 434 | + require.NoError(t, err) |
| 435 | + assert.Equal(t, models.NodeTypeWidget, componentType) |
| 436 | + }) |
| 437 | + |
| 438 | + t.Run("prefers component when action and trigger share the same name", func(t *testing.T) { |
| 439 | + action := impl.NewDummyAction(impl.DummyActionOptions{Name: "shared_name"}) |
| 440 | + trigger := impl.NewDummyTrigger(impl.DummyTriggerOptions{Name: "shared_name"}) |
| 441 | + |
| 442 | + r := ®istry.Registry{ |
| 443 | + Actions: map[string]core.Action{"shared_name": registry.NewPanicableAction(action)}, |
| 444 | + Triggers: map[string]core.Trigger{"shared_name": registry.NewPanicableTrigger(trigger)}, |
| 445 | + Integrations: map[string]core.Integration{}, |
| 446 | + Widgets: map[string]core.Widget{"shared_name": impl.NewDummyWidget(impl.DummyWidgetOptions{Name: "shared_name"})}, |
| 447 | + } |
| 448 | + |
| 449 | + componentType, err := r.ComponentType("shared_name") |
| 450 | + require.NoError(t, err) |
| 451 | + assert.Equal(t, models.NodeTypeComponent, componentType) |
| 452 | + }) |
| 453 | + |
| 454 | + t.Run("returns error when component is missing", func(t *testing.T) { |
| 455 | + r := ®istry.Registry{ |
| 456 | + Actions: map[string]core.Action{}, |
| 457 | + Triggers: map[string]core.Trigger{}, |
| 458 | + Integrations: map[string]core.Integration{}, |
| 459 | + Widgets: map[string]core.Widget{}, |
| 460 | + } |
| 461 | + |
| 462 | + componentType, err := r.ComponentType("missing_component") |
| 463 | + require.Error(t, err) |
| 464 | + assert.Empty(t, componentType) |
| 465 | + assert.EqualError(t, err, "component missing_component not found") |
| 466 | + }) |
| 467 | +} |
0 commit comments