Skip to content

Commit

Permalink
[builder]: Use testing.TB.TempDir instead of manually create and clea…
Browse files Browse the repository at this point in the history
…nup (#5469)

* Fix TestGenerateAndCompileDefault on windows

Fixes #5403

Signed-off-by: Bogdan Drutu <bogdandrutu@gmail.com>

* Update main_test.go
  • Loading branch information
bogdandrutu authored Jun 6, 2022
1 parent 6fb884b commit a4289b4
Showing 1 changed file with 7 additions and 10 deletions.
17 changes: 7 additions & 10 deletions cmd/builder/internal/builder/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,9 @@
package builder

import (
"io/ioutil"
"log"
"os"
"runtime"
"testing"
"time"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
Expand Down Expand Up @@ -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)
}

0 comments on commit a4289b4

Please sign in to comment.