Skip to content

Commit

Permalink
fix: test cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
theseion committed Jan 5, 2025
1 parent b97f998 commit 0fddcde
Showing 1 changed file with 5 additions and 13 deletions.
18 changes: 5 additions & 13 deletions runner/run_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -234,8 +234,7 @@ func (s *runTestSuite) BeforeTest(_ string, name string) {
}

// create a temporary file to hold the test
tempDir := s.T().TempDir()
testFileContents, err := os.CreateTemp(tempDir, "mock-test-*.yaml")
testFileContents, err := os.CreateTemp(s.T().TempDir(), "mock-test-*.yaml")
s.Require().NoError(err, "cannot create temporary file")
err = tmpl.Execute(testFileContents, vars)
s.Require().NoError(err, "cannot execute template")
Expand All @@ -248,17 +247,6 @@ func (s *runTestSuite) BeforeTest(_ string, name string) {
s.tempFileName = testFileContents.Name()
}

func (s *runTestSuite) AfterTest(_ string, _ string) {
err := os.Remove(s.logFilePath)
s.Require().NoError(err, "cannot remove log file")
log.Info().Msgf("Deleting temporary file '%s'", s.logFilePath)
if s.tempFileName != "" {
err = os.Remove(s.tempFileName)
s.Require().NoError(err, "cannot remove test file")
s.tempFileName = ""
}
}

func TestRunTestsTestSuite(t *testing.T) {
suite.Run(t, new(runTestSuite))
}
Expand Down Expand Up @@ -673,6 +661,7 @@ func (s *runTestSuite) TestEncodedRequest() {
client, err := ftwhttp.NewClient(ftwhttp.NewClientConfig())
s.Require().NoError(err)
ll, err := waflog.NewFTWLogLines(s.cfg)
s.T().Cleanup(func() { _ = ll.Cleanup() })
s.Require().NoError(err)

context := &TestRunContext{
Expand All @@ -684,6 +673,7 @@ func (s *runTestSuite) TestEncodedRequest() {
}
stage := s.ftwTests[0].Tests[0].Stages[0]
_check, err := check.NewCheck(s.cfg)
s.T().Cleanup(func() { _ = _check.Close() })
s.Require().NoError(err)

err = RunStage(context, _check, types.Test{}, stage)
Expand All @@ -695,6 +685,7 @@ func (s *runTestSuite) TestEncodedRequest_InvalidEncoding() {
client, err := ftwhttp.NewClient(ftwhttp.NewClientConfig())
s.Require().NoError(err)
ll, err := waflog.NewFTWLogLines(s.cfg)
s.T().Cleanup(func() { _ = ll.Cleanup() })
s.Require().NoError(err)

context := &TestRunContext{
Expand All @@ -706,6 +697,7 @@ func (s *runTestSuite) TestEncodedRequest_InvalidEncoding() {
}
stage := s.ftwTests[0].Tests[0].Stages[0]
_check, err := check.NewCheck(s.cfg)
s.T().Cleanup(func() { _ = _check.Close })
s.Require().NoError(err)

err = RunStage(context, _check, types.Test{}, stage)
Expand Down

0 comments on commit 0fddcde

Please sign in to comment.