Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: add a test to verify that deployment notifications work #1188

Merged
merged 1 commit into from
Apr 6, 2024
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
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.