fix(fs): rewrite test to avoid side effect

This commit is contained in:
Yicheng Qin 2014-04-09 13:11:23 -07:00
parent 1eff547af6
commit 6d77e4dfd6

View File

@ -1,21 +1,30 @@
package fs package fs
import ( import (
"io/ioutil"
"os"
"os/exec" "os/exec"
"strings" "strings"
"testing" "testing"
) )
func TestSetNOCOW(t *testing.T) { func TestSetNOCOW(t *testing.T) {
if IsBtrfs("/") { f, err := ioutil.TempFile(".", "etcdtest")
SetNOCOW("/") if err != nil {
cmd := exec.Command("lsattr", "/") t.Fatal("Failed creating temp file")
}
f.Close()
defer os.Remove(f.Name())
if IsBtrfs(f.Name()) {
SetNOCOW(f.Name())
cmd := exec.Command("lsattr", f.Name())
out, err := cmd.Output() out, err := cmd.Output()
if err != nil { if err != nil {
t.Fatal("Failed executing lsattr") t.Fatal("Failed executing lsattr")
} }
if strings.Contains(string(out), "---------------C") { if !strings.Contains(string(out), "---------------C") {
t.Fatal("Failed setting NOCOW:\n", out) t.Fatal("Failed setting NOCOW:\n", string(out))
} }
} }
} }