Skip to content

Commit

Permalink
fix: broken tests on windows (#348)
Browse files Browse the repository at this point in the history
  • Loading branch information
jabdr authored Aug 25, 2024
1 parent 1958c9b commit 0a1c2a2
Show file tree
Hide file tree
Showing 8 changed files with 21 additions and 4 deletions.
4 changes: 4 additions & 0 deletions check/base.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,3 +111,7 @@ func (c *FTWCheck) SetStartMarker(marker []byte) {
func (c *FTWCheck) SetEndMarker(marker []byte) {
c.log.WithEndMarker(marker)
}

func (c *FTWCheck) Close() error {
return c.log.Cleanup()
}
3 changes: 1 addition & 2 deletions check/logs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
package check

import (
"os"
"testing"

"github.com/google/uuid"
Expand Down Expand Up @@ -50,7 +49,7 @@ func (s *checkLogsTestSuite) SetupTest() {
}

func (s *checkLogsTestSuite) TearDownTest() {
err := os.Remove(s.logName)
err := s.check.Close()
s.Require().NoError(err)
}

Expand Down
2 changes: 2 additions & 0 deletions cmd/check_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ func (s *checkCmdTestSuite) SetupTest() {
s.Require().NoError(err)
n, err := testFileContents.WriteString(checkFileContents)
s.Require().NoError(err)
err = testFileContents.Close()
s.Require().NoError(err)
s.Equal(len(checkFileContents), n)

s.rootCmd = NewRootCommand()
Expand Down
2 changes: 2 additions & 0 deletions cmd/run_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,8 @@ func (s *runCmdTestSuite) SetupTest() {
s.Require().NoError(err)
err = tmpl.Execute(testFileContents, vars)
s.Require().NoError(err)
err = testFileContents.Close()
s.Require().NoError(err)

s.rootCmd = NewRootCommand()
s.rootCmd.AddCommand(NewRunCommand())
Expand Down
1 change: 1 addition & 0 deletions config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,7 @@ func (s *baseTestSuite) TestLoadPlatformOverrides() {
tempDir := s.T().TempDir()
overridesFile, err := os.CreateTemp(tempDir, "overrides.yaml")
s.Require().NoError(err)
defer overridesFile.Close()
_, err = overridesFile.WriteString(`---
version: "v0.0.0"
meta:
Expand Down
1 change: 1 addition & 0 deletions runner/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ func RunTest(runContext *TestRunContext, ftwTest *test.FTWTest) error {
if err != nil {
return err
}
defer ftwCheck.Close()
if err := RunStage(runContext, ftwCheck, testCase, stage); err != nil {
if err.Error() == "retry-once" {
log.Info().Msgf("Retrying test once: %s", testCase.IdString())
Expand Down
6 changes: 5 additions & 1 deletion runner/run_cloud_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,14 @@ func (s *runCloudTestSuite) BeforeTest(_ string, name string) {
tmpl, err := template.ParseFiles(fmt.Sprintf("testdata/%s.yaml", name))
s.Require().NoError(err)
// create a temporary file to hold the test
testFileContents, err := os.CreateTemp("testdata", "mock-test-*.yaml")
testdataDir, err := os.MkdirTemp(s.Suite.T().TempDir(), "testdata")
s.Require().NoError(err)
testFileContents, err := os.CreateTemp(testdataDir, "mock-test-*.yaml")
s.Require().NoError(err, "cannot create temporary file")
err = tmpl.Execute(testFileContents, vars)
s.Require().NoError(err, "cannot execute template")
err = testFileContents.Close()
s.Require().NoError(err)
// get tests from file
s.ftwTests, err = test.GetTestsFromFiles(testFileContents.Name())
s.Require().NoError(err, "cannot get tests from file")
Expand Down
6 changes: 5 additions & 1 deletion runner/run_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,9 @@ func (s *runTestSuite) setUpLogFileForTestServer() {
}
// if no file has been configured, create one and handle cleanup
if s.logFilePath == "" {
file, err := os.CreateTemp("", "go-ftw-test-*.log")
file, err := os.CreateTemp(s.T().TempDir(), "go-ftw-test-*.log")
s.Require().NoError(err)
err = file.Close()
s.Require().NoError(err)
s.logFilePath = file.Name()
}
Expand Down Expand Up @@ -239,6 +241,8 @@ func (s *runTestSuite) BeforeTest(_ string, name string) {
s.Require().NoError(err, "cannot create temporary file")
err = tmpl.Execute(testFileContents, vars)
s.Require().NoError(err, "cannot execute template")
err = testFileContents.Close()
s.Require().NoError(err)
// get tests from file
s.ftwTests, err = test.GetTestsFromFiles(testFileContents.Name())
s.Require().NoError(err, "cannot get tests from file")
Expand Down

0 comments on commit 0a1c2a2

Please sign in to comment.