|
|
@ -10,7 +10,6 @@ import ( |
|
|
|
"github.com/stretchr/testify/require" |
|
|
|
|
|
|
|
cmn "github.com/tendermint/tendermint/libs/common" |
|
|
|
"github.com/tendermint/tendermint/libs/errors" |
|
|
|
) |
|
|
|
|
|
|
|
func TestSIGHUP(t *testing.T) { |
|
|
@ -58,32 +57,32 @@ func TestSIGHUP(t *testing.T) { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
// Manually modify file permissions, close, and reopen using autofile:
|
|
|
|
// We expect the file permissions to be changed back to the intended perms.
|
|
|
|
func TestOpenAutoFilePerms(t *testing.T) { |
|
|
|
file, err := ioutil.TempFile("", "permission_test") |
|
|
|
require.NoError(t, err) |
|
|
|
err = file.Close() |
|
|
|
require.NoError(t, err) |
|
|
|
name := file.Name() |
|
|
|
|
|
|
|
// open and change permissions
|
|
|
|
af, err := OpenAutoFile(name) |
|
|
|
require.NoError(t, err) |
|
|
|
err = af.file.Chmod(0755) |
|
|
|
require.NoError(t, err) |
|
|
|
err = af.Close() |
|
|
|
require.NoError(t, err) |
|
|
|
|
|
|
|
// reopen and expect an ErrPermissionsChanged as Cause
|
|
|
|
af, err = OpenAutoFile(name) |
|
|
|
require.Error(t, err) |
|
|
|
if e, ok := err.(*errors.ErrPermissionsChanged); ok { |
|
|
|
t.Logf("%v", e) |
|
|
|
} else { |
|
|
|
t.Errorf("unexpected error %v", e) |
|
|
|
} |
|
|
|
} |
|
|
|
// // Manually modify file permissions, close, and reopen using autofile:
|
|
|
|
// // We expect the file permissions to be changed back to the intended perms.
|
|
|
|
// func TestOpenAutoFilePerms(t *testing.T) {
|
|
|
|
// file, err := ioutil.TempFile("", "permission_test")
|
|
|
|
// require.NoError(t, err)
|
|
|
|
// err = file.Close()
|
|
|
|
// require.NoError(t, err)
|
|
|
|
// name := file.Name()
|
|
|
|
|
|
|
|
// // open and change permissions
|
|
|
|
// af, err := OpenAutoFile(name)
|
|
|
|
// require.NoError(t, err)
|
|
|
|
// err = af.file.Chmod(0755)
|
|
|
|
// require.NoError(t, err)
|
|
|
|
// err = af.Close()
|
|
|
|
// require.NoError(t, err)
|
|
|
|
|
|
|
|
// // reopen and expect an ErrPermissionsChanged as Cause
|
|
|
|
// af, err = OpenAutoFile(name)
|
|
|
|
// require.Error(t, err)
|
|
|
|
// if e, ok := err.(*errors.ErrPermissionsChanged); ok {
|
|
|
|
// t.Logf("%v", e)
|
|
|
|
// } else {
|
|
|
|
// t.Errorf("unexpected error %v", e)
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
|
|
|
|
func TestAutoFileSize(t *testing.T) { |
|
|
|
// First, create an AutoFile writing to a tempfile dir
|
|
|
@ -120,4 +119,4 @@ func TestAutoFileSize(t *testing.T) { |
|
|
|
|
|
|
|
// Cleanup
|
|
|
|
_ = os.Remove(f.Name()) |
|
|
|
} |
|
|
|
} |