mirror of
https://github.com/pomerium/pomerium.git
synced 2025-08-02 16:30:17 +02:00
fileutil: add directory helpers, atomic file writing (#5477)
This commit is contained in:
parent
b9fd926618
commit
fbd1f34110
7 changed files with 133 additions and 27 deletions
30
internal/fileutil/atomic_test.go
Normal file
30
internal/fileutil/atomic_test.go
Normal file
|
@ -0,0 +1,30 @@
|
|||
package fileutil_test
|
||||
|
||||
import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"github.com/pomerium/pomerium/internal/fileutil"
|
||||
)
|
||||
|
||||
func TestWriteFileAtomically(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
dir := t.TempDir()
|
||||
|
||||
require.NoError(t, fileutil.WriteFileAtomically(filepath.Join(dir, "temp1.txt"), []byte("TEST"), 0o600))
|
||||
|
||||
entries, err := os.ReadDir(dir)
|
||||
require.NoError(t, err)
|
||||
|
||||
names := make([]string, len(entries))
|
||||
for i := range entries {
|
||||
names[i] = entries[i].Name()
|
||||
}
|
||||
|
||||
assert.Equal(t, []string{"temp1.txt"}, names)
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue