mirror of
https://github.com/grafana/grafana.git
synced 2024-12-02 05:29:42 -06:00
e829b50149
* Add CreateTempDir func and use it in publish packages logic * Fill err return in defer func
49 lines
1.5 KiB
Go
49 lines
1.5 KiB
Go
package fsutil
|
|
|
|
import (
|
|
"strings"
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
func TestCreateTempFile(t *testing.T) {
|
|
t.Run("empty suffix, expects pattern like: /var/folders/abcd/abcdefg/A/1137975807", func(t *testing.T) {
|
|
filePath, err := CreateTempFile("")
|
|
require.NoError(t, err)
|
|
|
|
pathParts := strings.Split(filePath, "/")
|
|
require.Greater(t, len(pathParts), 1)
|
|
require.Len(t, strings.Split(pathParts[len(pathParts)-1], "-"), 1)
|
|
})
|
|
|
|
t.Run("non-empty suffix, expects /var/folders/abcd/abcdefg/A/1137975807-foobar", func(t *testing.T) {
|
|
filePath, err := CreateTempFile("foobar")
|
|
require.NoError(t, err)
|
|
|
|
pathParts := strings.Split(filePath, "/")
|
|
require.Greater(t, len(pathParts), 1)
|
|
require.Len(t, strings.Split(pathParts[len(pathParts)-1], "-"), 2)
|
|
})
|
|
}
|
|
|
|
func TestCreateTempDir(t *testing.T) {
|
|
t.Run("empty suffix, expects pattern like: /var/folders/abcd/abcdefg/A/1137975807/", func(t *testing.T) {
|
|
filePath, err := CreateTempFile("")
|
|
require.NoError(t, err)
|
|
|
|
pathParts := strings.Split(filePath, "/")
|
|
require.Greater(t, len(pathParts), 1)
|
|
require.Len(t, strings.Split(pathParts[len(pathParts)-1], "-"), 1)
|
|
})
|
|
|
|
t.Run("non-empty suffix, expects /var/folders/abcd/abcdefg/A/1137975807-foobar/", func(t *testing.T) {
|
|
filePath, err := CreateTempFile("foobar")
|
|
require.NoError(t, err)
|
|
|
|
pathParts := strings.Split(filePath, "/")
|
|
require.Greater(t, len(pathParts), 1)
|
|
require.Len(t, strings.Split(pathParts[len(pathParts)-1], "-"), 2)
|
|
})
|
|
}
|