diff options
| author | 2022-08-31 17:31:21 +0200 | |
|---|---|---|
| committer | 2022-08-31 17:31:21 +0200 | |
| commit | 0245c606d77c8b99833ccc2c0923a298fb482236 (patch) | |
| tree | 16311e89656894f09cfaeb8b0f21b5ac9e4de502 /internal/api/client | |
| parent | [feature] add rate limit middleware (#741) (diff) | |
| download | gotosocial-0245c606d77c8b99833ccc2c0923a298fb482236.tar.xz | |
[chore] Test fixes (#788)
* use 'test' value for testrig storage backend
* update test dependency
* add WaitFor func in testrig
* use WaitFor function instead of time.Sleep
* tidy up tests
* make SentMessages a sync.map
* go fmt
Diffstat (limited to 'internal/api/client')
| -rw-r--r-- | internal/api/client/admin/mediacleanup_test.go | 38 | 
1 files changed, 19 insertions, 19 deletions
diff --git a/internal/api/client/admin/mediacleanup_test.go b/internal/api/client/admin/mediacleanup_test.go index 345402ad5..039bb7598 100644 --- a/internal/api/client/admin/mediacleanup_test.go +++ b/internal/api/client/admin/mediacleanup_test.go @@ -27,6 +27,7 @@ import (  	"github.com/stretchr/testify/suite"  	"github.com/superseriousbusiness/gotosocial/internal/api/client/admin" +	"github.com/superseriousbusiness/gotosocial/testrig"  )  type MediaCleanupTestSuite struct { @@ -47,15 +48,15 @@ func (suite *MediaCleanupTestSuite) TestMediaCleanup() {  	// we should have OK because our request was valid  	suite.Equal(http.StatusOK, recorder.Code) -	// Wait for async task to finish -	time.Sleep(1 * time.Second) - -	// Get media we prunes -	prunedAttachment, err := suite.db.GetAttachmentByID(context.Background(), testAttachment.ID) -	suite.NoError(err) - -	// the media should no longer be cached -	suite.False(*prunedAttachment.Cached) +	// the attachment should be updated in the database +	if !testrig.WaitFor(func() bool { +		if prunedAttachment, _ := suite.db.GetAttachmentByID(context.Background(), testAttachment.ID); prunedAttachment != nil { +			return !*prunedAttachment.Cached +		} +		return false +	}) { +		suite.FailNow("timed out waiting for attachment to be pruned") +	}  }  func (suite *MediaCleanupTestSuite) TestMediaCleanupNoArg() { @@ -73,15 +74,14 @@ func (suite *MediaCleanupTestSuite) TestMediaCleanupNoArg() {  	// we should have OK because our request was valid  	suite.Equal(http.StatusOK, recorder.Code) -	// Wait for async task to finish -	time.Sleep(1 * time.Second) - -	// Get media we prunes -	prunedAttachment, err := suite.db.GetAttachmentByID(context.Background(), testAttachment.ID) -	suite.NoError(err) - -	// the media should no longer be cached -	suite.False(*prunedAttachment.Cached) +	if !testrig.WaitFor(func() bool { +		if prunedAttachment, _ := suite.db.GetAttachmentByID(context.Background(), testAttachment.ID); prunedAttachment != nil { +			return !*prunedAttachment.Cached +		} +		return false +	}) { +		suite.FailNow("timed out waiting for attachment to be pruned") +	}  }  func (suite *MediaCleanupTestSuite) TestMediaCleanupNotOldEnough() { @@ -101,7 +101,7 @@ func (suite *MediaCleanupTestSuite) TestMediaCleanupNotOldEnough() {  	// Wait for async task to finish  	time.Sleep(1 * time.Second) -	// Get media we prunes +	// Get media we pruned  	prunedAttachment, err := suite.db.GetAttachmentByID(context.Background(), testAttachment.ID)  	suite.NoError(err)  | 
