Skip to content

Commit

Permalink
chore: validate that the deployment key is always set on deployments (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
jvmakine authored Feb 1, 2025
1 parent 928a6df commit da1913d
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
11 changes: 9 additions & 2 deletions backend/schemaservice/controllerstate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,15 @@ func TestDeploymentState(t *testing.T) {

deploymentKey := key.NewDeploymentKey("test-deployment")
err = cs.Publish(ctx, &schema.DeploymentCreatedEvent{
Key: deploymentKey,
Schema: &schema.Module{Name: "test"},
Key: deploymentKey,
Schema: &schema.Module{
Name: "test",
Runtime: &schema.ModuleRuntime{
Deployment: &schema.ModuleRuntimeDeployment{
DeploymentKey: deploymentKey,
},
},
},
})
assert.NoError(t, err)
view, err = cs.View(ctx)
Expand Down
4 changes: 4 additions & 0 deletions common/schema/events.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package schema

import (
"fmt"
"time"

"github.com/alecthomas/types/optional"
Expand Down Expand Up @@ -40,6 +41,9 @@ type DeploymentCreatedEvent struct {
func (r *DeploymentCreatedEvent) event() {}

func (r *DeploymentCreatedEvent) Validate() error {
if r.Schema.GetRuntime().GetDeployment().GetDeploymentKey().IsZero() {
return fmt.Errorf("deployment key is required")
}
return nil
}

Expand Down

0 comments on commit da1913d

Please sign in to comment.