-
Notifications
You must be signed in to change notification settings - Fork 0
/
cleanup_test.go
51 lines (34 loc) · 956 Bytes
/
cleanup_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package k6exec_test
import (
"os"
"path/filepath"
"strconv"
"strings"
"testing"
"github.com/grafana/k6exec"
"github.com/stretchr/testify/require"
)
func exists(t *testing.T, filename string) bool {
t.Helper()
_, err := os.Stat(filename) //nolint:forbidigo
return err == nil
}
//nolint:forbidigo
func TestCleanupState(t *testing.T) {
t.Parallel()
tmp := t.TempDir()
opts := &k6exec.Options{StateDir: tmp}
subdir := filepath.Join(tmp, strconv.Itoa(os.Getpid()))
require.NoError(t, os.MkdirAll(subdir, 0o700))
name := filepath.Join(subdir, "hello.txt")
err := os.WriteFile(name, []byte("Hello, World!\n"), 0o600)
require.NoError(t, err)
require.True(t, exists(t, name))
err = k6exec.CleanupState(opts)
require.NoError(t, err)
require.False(t, exists(t, subdir))
require.True(t, exists(t, tmp))
opts = &k6exec.Options{AppName: strings.Repeat("too long", 2048)}
err = k6exec.CleanupState(opts)
require.Error(t, err)
}