Skip to content

Commit

Permalink
chore: add a test to verify that deployment notifications work (#1188)
Browse files Browse the repository at this point in the history
  • Loading branch information
alecthomas authored Apr 6, 2024
1 parent 2a1d4d8 commit 8c7ed38
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 1 deletion.
17 changes: 17 additions & 0 deletions backend/controller/dal/dal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,14 @@ func TestDAL(t *testing.T) {
var testContent = bytes.Repeat([]byte("sometestcontentthatislongerthanthereadbuffer"), 100)
var testSHA = sha256.Sum(testContent)

deploymentChangesCh := dal.DeploymentChanges.Subscribe(nil)
deploymentChanges := []DeploymentNotification{}
go func() {
for change := range deploymentChangesCh {
deploymentChanges = append(deploymentChanges, change)
}
}()

t.Run("UpsertModule", func(t *testing.T) {
err = dal.UpsertModule(ctx, "go", "test")
assert.NoError(t, err)
Expand Down Expand Up @@ -336,6 +344,15 @@ func TestDAL(t *testing.T) {
err = dal.DeregisterRunner(ctx, model.NewRunnerKey("localhost", "8080"))
assert.IsError(t, err, ErrNotFound)
})

t.Run("VerifyDeploymentNotifications", func(t *testing.T) {
expectedDeploymentChanges := []DeploymentNotification{
{Message: optional.Some(Deployment{Language: "go", Module: "test", Schema: &schema.Module{Name: "test"}})},
{Message: optional.Some(Deployment{Language: "go", Module: "test", MinReplicas: 1, Schema: &schema.Module{Name: "test"}})},
}
assert.Equal(t, expectedDeploymentChanges, deploymentChanges,
assert.Exclude[model.DeploymentKey](), assert.Exclude[time.Time](), assert.IgnoreGoStringer())
})
}

func artefactContent(t testing.TB, artefacts []*model.Artefact) [][]byte {
Expand Down
1 change: 1 addition & 0 deletions backend/controller/dal/notify.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ type event struct {
}

func (d *DAL) runListener(ctx context.Context, conn *pgx.Conn) {
defer conn.Close(ctx)
logger := log.FromContext(ctx)

logger.Debugf("Starting DB listener")
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ require (
github.com/BurntSushi/toml v1.3.2
github.com/TBD54566975/scaffolder v0.8.0
github.com/TBD54566975/scaffolder/extensions/javascript v0.8.0
github.com/alecthomas/assert/v2 v2.7.0
github.com/alecthomas/assert/v2 v2.8.0
github.com/alecthomas/atomic v0.1.0-alpha2
github.com/alecthomas/concurrency v0.0.2
github.com/alecthomas/kong v0.9.0
Expand Down
2 changes: 2 additions & 0 deletions go.sum

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 8c7ed38

Please sign in to comment.