From 8c04686e7948217f5339a0350e964c8b2eed503c Mon Sep 17 00:00:00 2001 From: Rebecca Mahany-Horton Date: Tue, 14 Nov 2023 12:45:58 -0500 Subject: [PATCH] Update test with more realistic behavior (#1456) --- pkg/autoupdate/tuf/autoupdate_test.go | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/pkg/autoupdate/tuf/autoupdate_test.go b/pkg/autoupdate/tuf/autoupdate_test.go index adda6d00f..d8119b62c 100644 --- a/pkg/autoupdate/tuf/autoupdate_test.go +++ b/pkg/autoupdate/tuf/autoupdate_test.go @@ -67,7 +67,7 @@ func TestExecute_launcherUpdate(t *testing.T) { mockKnapsack := typesmocks.NewKnapsack(t) mockKnapsack.On("RootDirectory").Return(testRootDir) mockKnapsack.On("UpdateChannel").Return("nightly") - mockKnapsack.On("AutoupdateInterval").Return(100 * time.Millisecond) // Set the check interval to something short so we can make a couple requests to our test metadata server + mockKnapsack.On("AutoupdateInterval").Return(500 * time.Millisecond) mockKnapsack.On("AutoupdateInitialDelay").Return(0 * time.Second) mockKnapsack.On("AutoupdateErrorsStore").Return(s) mockKnapsack.On("TufServerURL").Return(tufServerUrl) @@ -103,10 +103,12 @@ func TestExecute_launcherUpdate(t *testing.T) { mockLibraryManager.On("TidyLibrary", binaryOsqueryd, mock.Anything).Return().Once() // Expect that we attempt to update the library - mockLibraryManager.On("Available", binaryOsqueryd, fmt.Sprintf("osqueryd-%s.tar.gz", testReleaseVersion)).Return(false) - mockLibraryManager.On("Available", binaryLauncher, fmt.Sprintf("launcher-%s.tar.gz", testReleaseVersion)).Return(false) - mockLibraryManager.On("AddToLibrary", binaryOsqueryd, currentOsqueryVersion, fmt.Sprintf("osqueryd-%s.tar.gz", testReleaseVersion), osquerydMetadata).Return(nil) - mockLibraryManager.On("AddToLibrary", binaryLauncher, currentLauncherVersion, fmt.Sprintf("launcher-%s.tar.gz", testReleaseVersion), launcherMetadata).Return(nil) + mockLibraryManager.On("Available", binaryOsqueryd, fmt.Sprintf("osqueryd-%s.tar.gz", testReleaseVersion)).Return(false).Once() + mockLibraryManager.On("Available", binaryOsqueryd, fmt.Sprintf("osqueryd-%s.tar.gz", testReleaseVersion)).Return(true).Maybe() // On subsequent iterations, no need to download again + mockLibraryManager.On("Available", binaryLauncher, fmt.Sprintf("launcher-%s.tar.gz", testReleaseVersion)).Return(false).Once() + mockLibraryManager.On("Available", binaryLauncher, fmt.Sprintf("launcher-%s.tar.gz", testReleaseVersion)).Return(true).Maybe() // On subsequent iterations, no need to download again + mockLibraryManager.On("AddToLibrary", binaryOsqueryd, currentOsqueryVersion, fmt.Sprintf("osqueryd-%s.tar.gz", testReleaseVersion), osquerydMetadata).Return(nil).Once() + mockLibraryManager.On("AddToLibrary", binaryLauncher, currentLauncherVersion, fmt.Sprintf("launcher-%s.tar.gz", testReleaseVersion), launcherMetadata).Return(nil).Once() // Let the autoupdater run for a bit -- it will shut itself down after a launcher update go autoupdater.Execute()