Merge pull request #182 from marineam/fix
env_file: fix broken test cases
This commit is contained in:
		| @@ -5,6 +5,7 @@ import ( | ||||
| 	"os" | ||||
| 	"path" | ||||
| 	"strings" | ||||
| 	"syscall" | ||||
| 	"testing" | ||||
| ) | ||||
|  | ||||
| @@ -41,6 +42,11 @@ func TestWriteEnvFileUpdate(t *testing.T) { | ||||
| 	fullPath := path.Join(dir, name) | ||||
| 	ioutil.WriteFile(fullPath, []byte(base), 0644) | ||||
|  | ||||
| 	oldStat, err := os.Stat(fullPath) | ||||
| 	if err != nil { | ||||
| 		t.Fatal("Unable to stat file: %v", err) | ||||
| 	} | ||||
|  | ||||
| 	ef := EnvFile{ | ||||
| 		File: &File{ | ||||
| 			Path: name, | ||||
| @@ -61,6 +67,15 @@ func TestWriteEnvFileUpdate(t *testing.T) { | ||||
| 	if string(contents) != expectUpdate { | ||||
| 		t.Fatalf("File has incorrect contents: %q", contents) | ||||
| 	} | ||||
|  | ||||
| 	newStat, err := os.Stat(fullPath) | ||||
| 	if err != nil { | ||||
| 		t.Fatal("Unable to stat file: %v", err) | ||||
| 	} | ||||
|  | ||||
| 	if oldStat.Sys().(*syscall.Stat_t).Ino == newStat.Sys().(*syscall.Stat_t).Ino { | ||||
| 		t.Fatal("File was not replaced: %s", fullPath) | ||||
| 	} | ||||
| } | ||||
|  | ||||
| func TestWriteEnvFileUpdateNoNewline(t *testing.T) { | ||||
| @@ -74,6 +89,11 @@ func TestWriteEnvFileUpdateNoNewline(t *testing.T) { | ||||
| 	fullPath := path.Join(dir, name) | ||||
| 	ioutil.WriteFile(fullPath, []byte(baseNoNewline), 0644) | ||||
|  | ||||
| 	oldStat, err := os.Stat(fullPath) | ||||
| 	if err != nil { | ||||
| 		t.Fatal("Unable to stat file: %v", err) | ||||
| 	} | ||||
|  | ||||
| 	ef := EnvFile{ | ||||
| 		File: &File{ | ||||
| 			Path: name, | ||||
| @@ -94,6 +114,15 @@ func TestWriteEnvFileUpdateNoNewline(t *testing.T) { | ||||
| 	if string(contents) != expectUpdate { | ||||
| 		t.Fatalf("File has incorrect contents: %q", contents) | ||||
| 	} | ||||
|  | ||||
| 	newStat, err := os.Stat(fullPath) | ||||
| 	if err != nil { | ||||
| 		t.Fatal("Unable to stat file: %v", err) | ||||
| 	} | ||||
|  | ||||
| 	if oldStat.Sys().(*syscall.Stat_t).Ino == newStat.Sys().(*syscall.Stat_t).Ino { | ||||
| 		t.Fatal("File was not replaced: %s", fullPath) | ||||
| 	} | ||||
| } | ||||
|  | ||||
| func TestWriteEnvFileCreate(t *testing.T) { | ||||
| @@ -170,8 +199,8 @@ func TestWriteEnvFileNoop(t *testing.T) { | ||||
| 		t.Fatal("Unable to stat file: %v", err) | ||||
| 	} | ||||
|  | ||||
| 	if oldStat.ModTime() != newStat.ModTime() { | ||||
| 		t.Fatal("File mtime changed.") | ||||
| 	if oldStat.Sys().(*syscall.Stat_t).Ino != newStat.Sys().(*syscall.Stat_t).Ino { | ||||
| 		t.Fatal("File was replaced: %s", fullPath) | ||||
| 	} | ||||
| } | ||||
|  | ||||
| @@ -186,6 +215,11 @@ func TestWriteEnvFileUpdateDos(t *testing.T) { | ||||
| 	fullPath := path.Join(dir, name) | ||||
| 	ioutil.WriteFile(fullPath, []byte(baseDos), 0644) | ||||
|  | ||||
| 	oldStat, err := os.Stat(fullPath) | ||||
| 	if err != nil { | ||||
| 		t.Fatal("Unable to stat file: %v", err) | ||||
| 	} | ||||
|  | ||||
| 	ef := EnvFile{ | ||||
| 		File: &File{ | ||||
| 			Path: name, | ||||
| @@ -206,6 +240,15 @@ func TestWriteEnvFileUpdateDos(t *testing.T) { | ||||
| 	if string(contents) != expectUpdate { | ||||
| 		t.Fatalf("File has incorrect contents: %q", contents) | ||||
| 	} | ||||
|  | ||||
| 	newStat, err := os.Stat(fullPath) | ||||
| 	if err != nil { | ||||
| 		t.Fatal("Unable to stat file: %v", err) | ||||
| 	} | ||||
|  | ||||
| 	if oldStat.Sys().(*syscall.Stat_t).Ino == newStat.Sys().(*syscall.Stat_t).Ino { | ||||
| 		t.Fatal("File was not replaced: %s", fullPath) | ||||
| 	} | ||||
| } | ||||
|  | ||||
| // A middle ground noop, values are unchanged but we did have a value. | ||||
| @@ -252,8 +295,8 @@ func TestWriteEnvFileDos2Unix(t *testing.T) { | ||||
| 		t.Fatal("Unable to stat file: %v", err) | ||||
| 	} | ||||
|  | ||||
| 	if oldStat.ModTime() != newStat.ModTime() { | ||||
| 		t.Fatal("File mtime changed.") | ||||
| 	if oldStat.Sys().(*syscall.Stat_t).Ino == newStat.Sys().(*syscall.Stat_t).Ino { | ||||
| 		t.Fatal("File was not replaced: %s", fullPath) | ||||
| 	} | ||||
| } | ||||
|  | ||||
| @@ -300,8 +343,8 @@ func TestWriteEnvFileEmpty(t *testing.T) { | ||||
| 		t.Fatal("Unable to stat file: %v", err) | ||||
| 	} | ||||
|  | ||||
| 	if oldStat.ModTime() != newStat.ModTime() { | ||||
| 		t.Fatal("File mtime changed.") | ||||
| 	if oldStat.Sys().(*syscall.Stat_t).Ino != newStat.Sys().(*syscall.Stat_t).Ino { | ||||
| 		t.Fatal("File was replaced: %s", fullPath) | ||||
| 	} | ||||
| } | ||||
|  | ||||
| @@ -368,8 +411,6 @@ func TestWriteEnvFileNameFailure(t *testing.T) { | ||||
| 	defer os.RemoveAll(dir) | ||||
|  | ||||
| 	name := "foo.conf" | ||||
| 	fullPath := path.Join(dir, name) | ||||
| 	ioutil.WriteFile(fullPath, []byte(base), 0000) | ||||
|  | ||||
| 	ef := EnvFile{ | ||||
| 		File: &File{ | ||||
|   | ||||
		Reference in New Issue
	
	Block a user