From af65a9a92f4055f041d5ce8065dbc38a1ffbe372 Mon Sep 17 00:00:00 2001 From: Gregory Ballantine Date: Fri, 2 Sep 2022 01:56:04 -0400 Subject: [PATCH] Fixed the FileShouldBeLocked test for CI --- util/file_test.go | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/util/file_test.go b/util/file_test.go index e3e0bd4..dc1078d 100644 --- a/util/file_test.go +++ b/util/file_test.go @@ -10,25 +10,26 @@ import ( // define our test suite struct type FileTestSuite struct { suite.Suite - TestFile string } // run before tests to set up func (s *FileTestSuite) SetupSuite() { - s.TestFile = "testfile.txt" // create the test file for file lock testing - file, _ := os.Create(s.TestFile) - file.Close() // do this just to make extra sure the file handle is closed + file1, _ := os.Create("testfile-locked.txt") + file1.Close() // do this just to make extra sure the file handle is closed + file2, _ := os.Create("testfile-unlocked.txt") + file2.Close() } // run after tests to clean up func (s *FileTestSuite) TearDownSuite() { // remove the test file since it's no longer needed - os.Remove(s.TestFile) + os.Remove("testfile-locked.txt") + os.Remove("testfile-unlocked.txt") } // test the filename extension removal works func (s *FileTestSuite) TestFilenameWithoutExtension() { - filename := FilenameWithoutExtension(s.TestFile) + filename := FilenameWithoutExtension("testfile.txt") if filename != "testfile" { s.T().Logf("FilenameWithoutExtension returned '%s'; it should be 'testfile'.", filename) @@ -37,24 +38,24 @@ func (s *FileTestSuite) TestFilenameWithoutExtension() { // test that IsFileLocked returns true when the file is active func (s *FileTestSuite) TestFileShouldBeLocked() { - file, err := os.Open(s.TestFile) + file, err := os.Open("testfile-locked.txt") if err != nil { - s.T().Logf("Unable to open file %s: %s", s.TestFile, err) + s.T().Logf("Unable to open file %s: %s", "testfile-locked.txt", err) } defer file.Close() - assert.True(s.T(), IsFileLocked(s.TestFile)) + assert.True(s.T(), IsFileLocked("testfile-locked.txt")) } // test that IsFileLocked returns false when the file is not active func (s *FileTestSuite) TestFileShouldNotBeLocked() { - file, err := os.Open(s.TestFile) + file, err := os.Open("testfile-unlocked.txt") if err != nil { - s.T().Logf("Unable to open file %s: %s", s.TestFile, err) + s.T().Logf("Unable to open file %s: %s", "testfile-unlocked.txt", err) } file.Close() // we want this closed now so it's NOT open! - assert.False(s.T(), IsFileLocked(s.TestFile)) + assert.False(s.T(), IsFileLocked("testfile-unlocked.txt")) } // this is needed to run the test suite