Esempio n. 1
0
func TestFileName(t *testing.T) {
	path, remover := util.CreateFileInTempDir("foo.txt")
	defer remover()

	file, err := NewFileModel(path)
	if err != nil {
		t.Logf("got an error: %s", err)
		t.FailNow()
	}

	if file.Name() != path {
		t.Errorf(util.FormatTestMessage("got incorrect name"), file.Name(), path)
	}
}
Esempio n. 2
0
func TestFileRemove(t *testing.T) {
	path, remover := util.CreateFileInTempDir("foo.txt")
	defer remover()

	file, err := NewFileModel(path)
	if err != nil {
		t.Logf("got an error: %s", err)
		t.FailNow()
	}

	file.Remove()
	if util.FileOrDirectoryExists(file.Name()) {
		t.Errorf("file should be gone, but it is not: %s", file.Name())
	}
}
Esempio n. 3
0
func TestFileReadWrite(t *testing.T) {
	path, remover := util.CreateFileInTempDir("foo.txt")
	defer remover()

	file, err := NewFileModel(path)
	if err != nil {
		t.Logf("got an error: %s", err)
		t.FailNow()
	}

	contents := file.Read()
	if contents != "" {
		t.Errorf(util.FormatTestMessage("file should be empty"), contents, path)
	}

	file.Write("testing")

	contents = file.Read()
	if contents != "testing" {
		t.Errorf(util.FormatTestMessage("file shouldn't be empty"), contents, path)
	}
}