Fixed the FileShouldBeLocked test for CI
Some checks failed
ci/woodpecker/push/woodpecker Pipeline failed
Some checks failed
ci/woodpecker/push/woodpecker Pipeline failed
This commit is contained in:
parent
925ad42cb1
commit
af65a9a92f
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user