Consul is a distributed, highly available, and data center aware solution to connect and configure applications across dynamic, distributed infrastructure.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

32 lines
771 B

package file
import (
"io/ioutil"
"os"
"path/filepath"
"testing"
"github.com/stretchr/testify/require"
)
// This doesn't really test the "atomic" part of this function. It really
// tests that it just writes the file properly. I would love to test this
// better but I'm not sure how. -mitchellh
func TestWriteAtomic(t *testing.T) {
require := require.New(t)
td, err := ioutil.TempDir("", "lib-file")
require.NoError(err)
defer os.RemoveAll(td)
// Create a subdir that doesn't exist to test that it is created
path := filepath.Join(td, "subdir", "file")
// Write
expected := []byte("hello")
require.NoError(WriteAtomic(path, expected))
// Read and verify
actual, err := ioutil.ReadFile(path)
require.NoError(err)
require.Equal(expected, actual)
}