|
| 1 | +// This file is part of arduino-flasher-cli. |
| 2 | +// |
| 3 | +// Copyright 2025 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-flasher-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 updater |
| 17 | + |
| 18 | +import ( |
| 19 | + "os" |
| 20 | + "testing" |
| 21 | + |
| 22 | + "github.com/arduino/go-paths-helper" |
| 23 | + "github.com/stretchr/testify/require" |
| 24 | +) |
| 25 | + |
| 26 | +func TestTempDir(t *testing.T) { |
| 27 | + userCacheDir, err := os.UserCacheDir() |
| 28 | + require.NoError(t, err) |
| 29 | + |
| 30 | + defaultTempDir, err := SetTempDir("download-", "") |
| 31 | + defer func() { _ = defaultTempDir.RemoveAll() }() |
| 32 | + require.NoError(t, err) |
| 33 | + require.DirExists(t, defaultTempDir.String()) |
| 34 | + require.Contains(t, defaultTempDir.Base(), "download-") |
| 35 | + require.Contains(t, defaultTempDir.String(), userCacheDir) |
| 36 | + |
| 37 | + customTempDir, err := SetTempDir("extract-", ".") |
| 38 | + defer func() { _ = customTempDir.RemoveAll() }() |
| 39 | + require.NoError(t, err) |
| 40 | + require.DirExists(t, customTempDir.String()) |
| 41 | + require.Contains(t, customTempDir.Base(), "extract-") |
| 42 | + currentDir, err := paths.New(".").Abs() |
| 43 | + require.NoError(t, err) |
| 44 | + require.Contains(t, customTempDir.String(), currentDir.String()) |
| 45 | +} |
0 commit comments