Consolidated the test file
Some checks failed
ci/woodpecker/push/woodpecker Pipeline failed

This commit is contained in:
Gregory Ballantine 2022-09-02 12:08:45 -04:00
parent 92d03f44dd
commit 96e64d0c37

View File

@ -10,26 +10,25 @@ import (
// define our test suite struct // define our test suite struct
type FileTestSuite struct { type FileTestSuite struct {
suite.Suite suite.Suite
TestFile string
} }
// run before tests to set up // run before tests to set up
func (s *FileTestSuite) SetupSuite() { func (s *FileTestSuite) SetupSuite() {
s.TestFile = "testfile.txt"
// create the test file for file lock testing // create the test file for file lock testing
file1, _ := os.Create("testfile-locked.txt") file, _ := os.Create(s.TestFile)
file1.Close() // do this just to make extra sure the file handle is closed file.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 // run after tests to clean up
func (s *FileTestSuite) TearDownSuite() { func (s *FileTestSuite) TearDownSuite() {
// remove the test file since it's no longer needed // remove the test file since it's no longer needed
os.Remove("testfile-locked.txt") os.Remove(s.TestFile)
os.Remove("testfile-unlocked.txt")
} }
// test the filename extension removal works // test the filename extension removal works
func (s *FileTestSuite) TestFilenameWithoutExtension() { func (s *FileTestSuite) TestFilenameWithoutExtension() {
filename := FilenameWithoutExtension("testfile.txt") filename := FilenameWithoutExtension(s.TestFile)
if filename != "testfile" { if filename != "testfile" {
s.T().Logf("FilenameWithoutExtension returned '%s'; it should be 'testfile'.", filename) s.T().Logf("FilenameWithoutExtension returned '%s'; it should be 'testfile'.", filename)
@ -38,25 +37,25 @@ func (s *FileTestSuite) TestFilenameWithoutExtension() {
// test that IsFileLocked returns true when the file is active // test that IsFileLocked returns true when the file is active
func (s *FileTestSuite) TestFileShouldBeLocked() { func (s *FileTestSuite) TestFileShouldBeLocked() {
file, err := os.Open("testfile-locked.txt") file, err := os.Open(s.TestFile)
if err != nil { if err != nil {
s.T().Logf("Unable to open file %s: %s", "testfile-locked.txt", err) s.T().Logf("Unable to open file %s: %s", s.TestFile, err)
} }
assert.True(s.T(), IsFileLocked("testfile-locked.txt")) assert.True(s.T(), IsFileLocked(s.TestFile))
file.Close() file.Close()
} }
// test that IsFileLocked returns false when the file is not active // test that IsFileLocked returns false when the file is not active
func (s *FileTestSuite) TestFileShouldNotBeLocked() { func (s *FileTestSuite) TestFileShouldNotBeLocked() {
file, err := os.Open("testfile-unlocked.txt") file, err := os.Open(s.TestFile)
if err != nil { if err != nil {
s.T().Logf("Unable to open file %s: %s", "testfile-unlocked.txt", err) s.T().Logf("Unable to open file %s: %s", s.TestFile, err)
} }
file.Close() // we want this closed now so it's NOT open! file.Close() // we want this closed now so it's NOT open!
assert.False(s.T(), IsFileLocked("testfile-unlocked.txt")) assert.False(s.T(), IsFileLocked(s.TestFile))
} }
// this is needed to run the test suite // this is needed to run the test suite