From a4289b45ff420757199d61e96d7e9a6e332e061f Mon Sep 17 00:00:00 2001 From: Bogdan Drutu Date: Mon, 6 Jun 2022 08:31:16 -0700 Subject: [PATCH] [builder]: Use testing.TB.TempDir instead of manually create and cleanup (#5469) * Fix TestGenerateAndCompileDefault on windows Fixes https://github.com/open-telemetry/opentelemetry-collector/issues/5403 Signed-off-by: Bogdan Drutu * Update main_test.go --- cmd/builder/internal/builder/main_test.go | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/cmd/builder/internal/builder/main_test.go b/cmd/builder/internal/builder/main_test.go index ffc25abd6fa..03057bb4b72 100644 --- a/cmd/builder/internal/builder/main_test.go +++ b/cmd/builder/internal/builder/main_test.go @@ -15,11 +15,9 @@ package builder import ( - "io/ioutil" - "log" - "os" "runtime" "testing" + "time" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" @@ -48,17 +46,16 @@ func TestGenerateAndCompileDefault(t *testing.T) { if runtime.GOOS == "windows" { t.Skip("skipping the test on Windows, see https://github.com/open-telemetry/opentelemetry-collector/issues/5403") } - dir, err := ioutil.TempDir("", "default") - if err != nil { - log.Fatal(err) - } - defer os.RemoveAll(dir) cfg := NewDefaultConfig() - cfg.Distribution.OutputPath = dir + cfg.Distribution.OutputPath = t.TempDir() // we override this version, otherwise this would break during releases - cfg.Distribution.OtelColVersion = "0.38.0" + cfg.Distribution.OtelColVersion = "0.52.0" assert.NoError(t, cfg.Validate()) 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) }