Skip to content

Commit

Permalink
fix: query ModuleConfiguration via DAL (#1601)
Browse files Browse the repository at this point in the history
  • Loading branch information
deniseli authored May 29, 2024
1 parent d2e8e1e commit 93f0d7f
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 8 deletions.
26 changes: 26 additions & 0 deletions backend/controller/dal/dal.go
Original file line number Diff line number Diff line change
Expand Up @@ -1147,6 +1147,32 @@ func (d *DAL) GetActiveRunners(ctx context.Context) ([]Runner, error) {
}), nil
}

func (d *DAL) GetModuleConfiguration(ctx context.Context, module optional.Option[string], name string) ([]byte, error) {
b, err := d.db.GetModuleConfiguration(ctx, module, name)
if err != nil {
return nil, translatePGError(err)
}
return b, nil
}

func (d *DAL) SetModuleConfiguration(ctx context.Context, module optional.Option[string], name string, value []byte) error {
err := d.db.SetModuleConfiguration(ctx, module, name, value)
return translatePGError(err)
}

func (d *DAL) UnsetModuleConfiguration(ctx context.Context, module optional.Option[string], name string) error {
err := d.db.UnsetModuleConfiguration(ctx, module, name)
return translatePGError(err)
}

func (d *DAL) ListModuleConfiguration(ctx context.Context) ([]sql.ModuleConfiguration, error) {
l, err := d.db.ListModuleConfiguration(ctx)
if err != nil {
return nil, translatePGError(err)
}
return l, nil
}

// Check if a deployment exists that exactly matches the given artefacts and schema.
func (*DAL) checkForExistingDeployments(ctx context.Context, tx *sql.Tx, moduleSchema *schema.Module, artefacts []DeploymentArtefact) (model.DeploymentKey, error) {
schemaBytes, err := schema.ModuleToBytes(moduleSchema)
Expand Down
16 changes: 8 additions & 8 deletions backend/controller/dal/dal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -445,15 +445,15 @@ func TestModuleConfiguration(t *testing.T) {
for _, test := range tests {
t.Run(test.TestName, func(t *testing.T) {
if test.PresetGlobal {
err := dal.db.SetModuleConfiguration(ctx, optional.None[string](), "configname", []byte(`"qwerty"`))
err := dal.SetModuleConfiguration(ctx, optional.None[string](), "configname", []byte(`"qwerty"`))
assert.NoError(t, err)
}
err := dal.db.SetModuleConfiguration(ctx, test.ModuleSet, "configname", b)
err := dal.SetModuleConfiguration(ctx, test.ModuleSet, "configname", b)
assert.NoError(t, err)
gotBytes, err := dal.db.GetModuleConfiguration(ctx, test.ModuleGet, "configname")
gotBytes, err := dal.GetModuleConfiguration(ctx, test.ModuleGet, "configname")
assert.NoError(t, err)
assert.Equal(t, b, gotBytes)
err = dal.db.UnsetModuleConfiguration(ctx, test.ModuleGet, "configname")
err = dal.UnsetModuleConfiguration(ctx, test.ModuleGet, "configname")
assert.NoError(t, err)
})
}
Expand All @@ -476,14 +476,14 @@ func TestModuleConfiguration(t *testing.T) {

// Insert entries in a separate order from how they should be returned to
// test sorting logic in the SQL query
err := dal.db.SetModuleConfiguration(ctx, sortedList[1].Module, sortedList[1].Name, []byte(`""`))
err := dal.SetModuleConfiguration(ctx, sortedList[1].Module, sortedList[1].Name, []byte(`""`))
assert.NoError(t, err)
err = dal.db.SetModuleConfiguration(ctx, sortedList[2].Module, sortedList[2].Name, []byte(`""`))
err = dal.SetModuleConfiguration(ctx, sortedList[2].Module, sortedList[2].Name, []byte(`""`))
assert.NoError(t, err)
err = dal.db.SetModuleConfiguration(ctx, sortedList[0].Module, sortedList[0].Name, []byte(`""`))
err = dal.SetModuleConfiguration(ctx, sortedList[0].Module, sortedList[0].Name, []byte(`""`))
assert.NoError(t, err)

gotList, err := dal.db.ListModuleConfiguration(ctx)
gotList, err := dal.ListModuleConfiguration(ctx)
assert.NoError(t, err)
for i := range sortedList {
assert.Equal(t, sortedList[i].Module, gotList[i].Module)
Expand Down

0 comments on commit 93f0d7f

Please sign in to comment.