diff --git a/cmd/builder/internal/builder/main.go b/cmd/builder/internal/builder/main.go index 89988bd398f..fd06473e629 100644 --- a/cmd/builder/internal/builder/main.go +++ b/cmd/builder/internal/builder/main.go @@ -162,5 +162,6 @@ func processAndWrite(cfg Config, tmpl *template.Template, outFile string, tmplPa return err } + defer out.Close() return tmpl.Execute(out, tmplParams) } diff --git a/cmd/builder/internal/builder/main_test.go b/cmd/builder/internal/builder/main_test.go index e9f2fbbd303..57b73c0e043 100644 --- a/cmd/builder/internal/builder/main_test.go +++ b/cmd/builder/internal/builder/main_test.go @@ -10,7 +10,6 @@ import ( "path/filepath" "runtime" "testing" - "time" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" @@ -36,25 +35,21 @@ func TestGenerateInvalidOutputPath(t *testing.T) { } func TestSkipGenerate(t *testing.T) { - if runtime.GOOS == "windows" { - t.Skip("skipping the test on Windows, see https://github.com/open-telemetry/opentelemetry-collector/issues/5403") - } - cfg := NewDefaultConfig() cfg.Distribution.OutputPath = t.TempDir() cfg.SkipGenerate = true err := Generate(cfg) require.NoError(t, err) outputFile, err := os.Open(cfg.Distribution.OutputPath) + defer func() { + require.NoError(t, outputFile.Close()) + }() require.NoError(t, err) _, err = outputFile.Readdirnames(1) require.ErrorIs(t, err, io.EOF, "skip generate should leave output directory empty") } func TestGenerateAndCompile(t *testing.T) { - if runtime.GOOS == "windows" { - t.Skip("skipping the test on Windows, see https://github.com/open-telemetry/opentelemetry-collector/issues/5403") - } // This test is dependent on the current file structure. // The goal is find the root of the repo so we can replace the root module. _, thisFile, _, _ := runtime.Caller(0) @@ -129,8 +124,4 @@ func TestGenerateAndCompile(t *testing.T) { require.NoError(t, GenerateAndCompile(cfg)) }) } - - // Sleep for 1 second to make sure all processes using the files are completed - // (on Windows fail to delete temp dir otherwise). - time.Sleep(1 * time.Second) }