|
| 1 | +package changesets |
| 2 | + |
| 3 | +import ( |
| 4 | + "net/http" |
| 5 | + "testing" |
| 6 | + |
| 7 | + "github.com/google/uuid" |
| 8 | + "github.com/stretchr/testify/assert" |
| 9 | + "github.com/stretchr/testify/require" |
| 10 | + "github.com/superplanehq/superplane/pkg/configuration" |
| 11 | + "github.com/superplanehq/superplane/pkg/core" |
| 12 | + "github.com/superplanehq/superplane/pkg/crypto" |
| 13 | + "github.com/superplanehq/superplane/pkg/models" |
| 14 | + "github.com/superplanehq/superplane/pkg/registry" |
| 15 | +) |
| 16 | + |
| 17 | +type testOutputChannelComponent struct { |
| 18 | + channels []core.OutputChannel |
| 19 | +} |
| 20 | + |
| 21 | +func (c *testOutputChannelComponent) Name() string { return "test-component" } |
| 22 | + |
| 23 | +func (c *testOutputChannelComponent) Label() string { return "Test Component" } |
| 24 | + |
| 25 | +func (c *testOutputChannelComponent) Description() string { return "" } |
| 26 | + |
| 27 | +func (c *testOutputChannelComponent) Documentation() string { return "" } |
| 28 | + |
| 29 | +func (c *testOutputChannelComponent) Icon() string { return "" } |
| 30 | + |
| 31 | +func (c *testOutputChannelComponent) Color() string { return "" } |
| 32 | + |
| 33 | +func (c *testOutputChannelComponent) ExampleOutput() map[string]any { return nil } |
| 34 | + |
| 35 | +func (c *testOutputChannelComponent) OutputChannels(any) []core.OutputChannel { return c.channels } |
| 36 | + |
| 37 | +func (c *testOutputChannelComponent) Configuration() []configuration.Field { return nil } |
| 38 | + |
| 39 | +func (c *testOutputChannelComponent) Setup(core.SetupContext) error { return nil } |
| 40 | + |
| 41 | +func (c *testOutputChannelComponent) ProcessQueueItem(core.ProcessQueueContext) (*uuid.UUID, error) { |
| 42 | + return nil, nil |
| 43 | +} |
| 44 | + |
| 45 | +func (c *testOutputChannelComponent) Execute(core.ExecutionContext) error { return nil } |
| 46 | + |
| 47 | +func (c *testOutputChannelComponent) Actions() []core.Action { return nil } |
| 48 | + |
| 49 | +func (c *testOutputChannelComponent) HandleAction(core.ActionContext) error { return nil } |
| 50 | + |
| 51 | +func (c *testOutputChannelComponent) HandleWebhook(core.WebhookRequestContext) (int, *core.WebhookResponseBody, error) { |
| 52 | + return http.StatusOK, nil, nil |
| 53 | +} |
| 54 | + |
| 55 | +func (c *testOutputChannelComponent) Cancel(core.ExecutionContext) error { return nil } |
| 56 | + |
| 57 | +func (c *testOutputChannelComponent) Cleanup(core.SetupContext) error { return nil } |
| 58 | + |
| 59 | +func TestValidateSourceNodeOutputChannel(t *testing.T) { |
| 60 | + reg, err := registry.NewRegistry(&crypto.NoOpEncryptor{}, registry.HTTPOptions{}) |
| 61 | + require.NoError(t, err) |
| 62 | + |
| 63 | + t.Run("unresolvable source component stays soft", func(t *testing.T) { |
| 64 | + err := ValidateSourceNodeOutputChannel( |
| 65 | + reg, |
| 66 | + models.Node{ |
| 67 | + ID: "node-a", |
| 68 | + Type: models.NodeTypeComponent, |
| 69 | + Ref: models.NodeRef{ |
| 70 | + Component: &models.ComponentRef{Name: "missing-component"}, |
| 71 | + }, |
| 72 | + }, |
| 73 | + "default", |
| 74 | + ) |
| 75 | + |
| 76 | + require.NoError(t, err) |
| 77 | + }) |
| 78 | + |
| 79 | + t.Run("wrong channel on resolvable component returns error", func(t *testing.T) { |
| 80 | + reg.Components["test-component"] = &testOutputChannelComponent{ |
| 81 | + channels: []core.OutputChannel{ |
| 82 | + {Name: "success"}, |
| 83 | + {Name: "failure"}, |
| 84 | + }, |
| 85 | + } |
| 86 | + |
| 87 | + err := ValidateSourceNodeOutputChannel( |
| 88 | + reg, |
| 89 | + models.Node{ |
| 90 | + ID: "node-a", |
| 91 | + Type: models.NodeTypeComponent, |
| 92 | + Ref: models.NodeRef{ |
| 93 | + Component: &models.ComponentRef{Name: "test-component"}, |
| 94 | + }, |
| 95 | + }, |
| 96 | + "default", |
| 97 | + ) |
| 98 | + |
| 99 | + require.Error(t, err) |
| 100 | + assert.Contains(t, err.Error(), `source node node-a does not have output channel "default"`) |
| 101 | + assert.Contains(t, err.Error(), "success") |
| 102 | + assert.Contains(t, err.Error(), "failure") |
| 103 | + }) |
| 104 | +} |
0 commit comments