From adb263c6074ff64fd9df2dbfe97324f49d38aa27 Mon Sep 17 00:00:00 2001 From: Martin Angers Date: Mon, 16 Dec 2024 16:41:24 -0500 Subject: [PATCH] Remove obsolete todo, start test --- server/datastore/mysql/software_installers.go | 30 +++++++++---------- .../mysql/software_installers_test.go | 5 ++++ 2 files changed, 19 insertions(+), 16 deletions(-) diff --git a/server/datastore/mysql/software_installers.go b/server/datastore/mysql/software_installers.go index 31073630645a..bb42b55c9d77 100644 --- a/server/datastore/mysql/software_installers.go +++ b/server/datastore/mysql/software_installers.go @@ -832,8 +832,6 @@ func (ds *Datastore) CleanupUnusedSoftwareInstallers(ctx context.Context, softwa } func (ds *Datastore) BatchSetSoftwareInstallers(ctx context.Context, tmID *uint, installers []*fleet.UploadSoftwareInstallerPayload) error { - // TODO(mna): handle the include/exclude labels... - const upsertSoftwareTitles = ` INSERT INTO software_titles (name, source, browser) @@ -1003,27 +1001,27 @@ ON DUPLICATE KEY UPDATE ` const loadSoftwareInstallerID = ` -SELECT - id -FROM - software_installers -WHERE +SELECT + id +FROM + software_installers +WHERE global_or_team_id = ? AND -- this is guaranteed to select a single title_id, due to unique index - title_id IN (SELECT id FROM software_titles WHERE name = ? AND source = ? AND browser = '') + title_id IN (SELECT id FROM software_titles WHERE name = ? AND source = ? AND browser = '') ` const deleteInstallerLabelsNotInList = ` DELETE - software_installer_labels + software_installer_labels WHERE software_installer_id = ? AND label_id NOT IN (?) ` const deleteAllInstallerLabels = ` -DELETE - software_installer_labels +DELETE + software_installer_labels WHERE software_installer_id = ? ` @@ -1042,11 +1040,11 @@ ON DUPLICATE KEY UPDATE ` const loadExistingInstallerLabels = ` -SELECT +SELECT label_id, - exclude -FROM - software_installer_labels + exclude +FROM + software_installer_labels WHERE software_installer_id = ? ` @@ -1333,7 +1331,7 @@ WHERE } } - // perform side effects if this was an update + // perform side effects if this was an update (related to pending (un)install requests) if len(existing) > 0 { if err := ds.runInstallerUpdateSideEffectsInTransaction( ctx, diff --git a/server/datastore/mysql/software_installers_test.go b/server/datastore/mysql/software_installers_test.go index 347ffde4c3bb..71849af02761 100644 --- a/server/datastore/mysql/software_installers_test.go +++ b/server/datastore/mysql/software_installers_test.go @@ -36,6 +36,7 @@ func TestSoftwareInstallers(t *testing.T) { {"DeleteSoftwareInstallers", testDeleteSoftwareInstallers}, {"GetHostLastInstallData", testGetHostLastInstallData}, {"GetOrGenerateSoftwareInstallerTitleID", testGetOrGenerateSoftwareInstallerTitleID}, + {"BatchSetSoftwareInstallersScopedViaLabels", testBatchSetSoftwareInstallersScopedViaLabels}, } for _, c := range cases { @@ -1361,3 +1362,7 @@ func testGetOrGenerateSoftwareInstallerTitleID(t *testing.T, ds *Datastore) { }) } } + +func testBatchSetSoftwareInstallersScopedViaLabels(t *testing.T, ds *Datastore) { + ctx := context.Background() +}