Browse Source

fix(fs): rewrite test to avoid side effect

Yicheng Qin 11 years ago
parent
commit
6d77e4dfd6
1 changed files with 14 additions and 5 deletions
  1. 14 5
      pkg/fs/fs_test.go

+ 14 - 5
pkg/fs/fs_test.go

@@ -1,21 +1,30 @@
 package fs
 
 import (
+	"io/ioutil"
+	"os"
 	"os/exec"
 	"strings"
 	"testing"
 )
 
 func TestSetNOCOW(t *testing.T) {
-	if IsBtrfs("/") {
-		SetNOCOW("/")
-		cmd := exec.Command("lsattr", "/")
+	f, err := ioutil.TempFile(".", "etcdtest")
+	if err != nil {
+		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()
 		if err != nil {
 			t.Fatal("Failed executing lsattr")
 		}
-		if strings.Contains(string(out), "---------------C") {
-			t.Fatal("Failed setting NOCOW:\n", out)
+		if !strings.Contains(string(out), "---------------C") {
+			t.Fatal("Failed setting NOCOW:\n", string(out))
 		}
 	}
 }