Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 2 additions & 16 deletions internal/antest/helpers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package antest

import (
"os"
"runtime"
"testing"

"github.com/stretchr/testify/require"
Expand Down Expand Up @@ -55,7 +54,7 @@ func prepareBadDoc(t testing.TB, kind string, invalidFormat bool) (string, func(

switch kind {
case "yaml", "yml":
f, err := os.CreateTemp(workaroundTempDir(t)(), "*.yaml")
f, err := os.CreateTemp(t.TempDir(), "*.yaml")
require.NoError(t, err)
file = f.Name()

Expand All @@ -73,7 +72,7 @@ info:
}

case "json":
f, err := os.CreateTemp(workaroundTempDir(t)(), "*.json")
f, err := os.CreateTemp(t.TempDir(), "*.json")
require.NoError(t, err)
file = f.Name()

Expand Down Expand Up @@ -101,16 +100,3 @@ info:

return file, func() {}
}

func workaroundTempDir(t testing.TB) func() string {
// Workaround for go testing bug on Windows: https://github.com/golang/go/issues/71544
// On windows, t.TempDir() doesn't properly release file handles yet,
// se we just leave it unchecked (no cleanup would take place).
if runtime.GOOS == "windows" {
return func() string {
return ""
}
}

return t.TempDir
}
18 changes: 2 additions & 16 deletions internal/debug/debug_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,14 @@ package debug

import (
"os"
"runtime"
"testing"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)

func TestDebug(t *testing.T) {
tmpFile, err := os.CreateTemp(workaroundTempDir(t)(), "debug-test")
tmpFile, err := os.CreateTemp(t.TempDir(), "debug-test")
require.NoError(t, err)

output = tmpFile
Expand All @@ -39,7 +38,7 @@ func TestDebug(t *testing.T) {

assert.Contains(t, string(flushed), "A debug: a string")

tmpEmptyFile, err := os.CreateTemp(workaroundTempDir(t)(), "debug-test")
tmpEmptyFile, err := os.CreateTemp(t.TempDir(), "debug-test")
require.NoError(t, err)
tmpEmpty := tmpEmptyFile.Name()
testLogger = GetLogger("test", false)
Expand All @@ -52,16 +51,3 @@ func TestDebug(t *testing.T) {

assert.Empty(t, flushed)
}

func workaroundTempDir(t testing.TB) func() string {
// Workaround for go testing bug on Windows: https://github.com/golang/go/issues/71544
// On windows, t.TempDir() doesn't properly release file handles yet,
// se we just leave it unchecked (no cleanup would take place).
if runtime.GOOS == "windows" {
return func() string {
return ""
}
}

return t.TempDir
}
Loading