mirror of
https://github.com/fluencelabs/tendermint
synced 2025-04-25 14:52:17 +00:00
[common] add a test for WriteFileAtomic
This commit is contained in:
parent
b25aa3b472
commit
d1ca2c6f83
29
common/os_test.go
Normal file
29
common/os_test.go
Normal file
@ -0,0 +1,29 @@
|
||||
package common
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
func TestWriteFileAtomic(t *testing.T) {
|
||||
data := []byte("Becatron")
|
||||
fname := fmt.Sprintf("/tmp/write-file-atomic-test-%v.txt", time.Now().UnixNano())
|
||||
err := WriteFileAtomic(fname, data, 0664)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
rData, err := ioutil.ReadFile(fname)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if !bytes.Equal(data, rData) {
|
||||
t.Fatalf("data mismatch: %v != %v", data, rData)
|
||||
}
|
||||
if err := os.Remove(fname); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user