mirror of
https://github.com/nspcc-dev/neo-go.git
synced 2024-12-23 13:41:37 +00:00
aefb6f9fee
Solution: Use `file/filepath` package to construct expected path. This package is OS-aware, see https://github.com/golang/go/issues/30616.
32 lines
799 B
Go
32 lines
799 B
Go
package io
|
|
|
|
import (
|
|
"os"
|
|
"path/filepath"
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
func TestMakeDirForFile_HappyPath(t *testing.T) {
|
|
tempDir := t.TempDir()
|
|
filePath := filepath.Join(tempDir, "testDir", "testFile.test")
|
|
err := MakeDirForFile(filePath, "test")
|
|
require.NoError(t, err)
|
|
|
|
f, errChDir := os.Create(filePath)
|
|
require.NoError(t, errChDir)
|
|
require.NoError(t, f.Close())
|
|
}
|
|
|
|
func TestMakeDirForFile_Negative(t *testing.T) {
|
|
tempDir := t.TempDir()
|
|
filePath := filepath.Join(tempDir, "testFile.test")
|
|
f, err := os.Create(filePath)
|
|
require.NoError(t, err)
|
|
require.NoError(t, f.Close())
|
|
|
|
filePath = filepath.Join(filePath, "error")
|
|
err = MakeDirForFile(filePath, "test")
|
|
require.Errorf(t, err, "could not create dir for test: mkdir %s : not a directory", filePath)
|
|
}
|