Skip to content

Commit 72941fc

Browse files
committed
testsuite: Added helper functions to handle test envs
1 parent 5332ffd commit 72941fc

File tree

1 file changed

+59
-0
lines changed

1 file changed

+59
-0
lines changed

testsuite/env.go

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
// This file is part of arduino-cli.
2+
//
3+
// Copyright 2022 ARDUINO SA (http://www.arduino.cc/)
4+
//
5+
// This software is released under the GNU General Public License version 3,
6+
// which covers the main part of arduino-cli.
7+
// The terms of this license can be found at:
8+
// https://www.gnu.org/licenses/gpl-3.0.en.html
9+
//
10+
// You can be released from the requirements of the above licenses by purchasing
11+
// a commercial license. Buying such a license is mandatory if you want to
12+
// modify or otherwise use the software for commercial activities involving the
13+
// Arduino software without disclosing the source code of your own applications.
14+
// To purchase a commercial license, send an email to license@arduino.cc.
15+
16+
package integrationtest
17+
18+
import (
19+
"testing"
20+
21+
"github.com/arduino/go-paths-helper"
22+
"github.com/stretchr/testify/require"
23+
)
24+
25+
// Environment is a test environment for the test suite.
26+
type Environment struct {
27+
rootDir *paths.Path
28+
downloadsDir *paths.Path
29+
t *require.Assertions
30+
}
31+
32+
// SharedDownloadDir returns the shared downloads directory.
33+
func SharedDownloadDir(t *testing.T) *paths.Path {
34+
downloadsDir := paths.TempDir().Join("arduino-cli-test-suite-staging")
35+
require.NoError(t, downloadsDir.MkdirAll())
36+
return downloadsDir
37+
}
38+
39+
// NewEnvironment creates a new test environment.
40+
func NewEnvironment(t *testing.T) *Environment {
41+
downloadsDir := SharedDownloadDir(t)
42+
rootDir, err := paths.MkTempDir("", "arduino-cli-test-suite")
43+
require.NoError(t, err)
44+
return &Environment{
45+
rootDir: rootDir,
46+
downloadsDir: downloadsDir,
47+
t: require.New(t),
48+
}
49+
}
50+
51+
// CleanUp removes the test environment.
52+
func (e *Environment) CleanUp() {
53+
e.t.NoError(e.rootDir.RemoveAll())
54+
}
55+
56+
// Root returns the root dir of the environment.
57+
func (e *Environment) Root() *paths.Path {
58+
return e.rootDir
59+
}

0 commit comments

Comments
 (0)