Exemplo n.º 1
0
func TestFileCreate(t *testing.T) {
	path, remover := util.CreateTempDir("foo")
	defer remover()

	file_path := filepath.Join(path, "foo.txt")

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

	if file.Name() != file_path {
		t.Errorf(util.FormatTestMessage("got incorrect name"), file.Name(), file_path)
	}

	contents := file.Read()
	if contents != "testing" {
		t.Errorf(util.FormatTestMessage("file contents are incorrect"), contents, "testing")
	}

	file.Remove()
	if util.FileOrDirectoryExists(file.Name()) {
		t.Errorf("file should be gone, but it is not: %s", file.Name())
	}
}
Exemplo n.º 2
0
func TestDirectoryName(t *testing.T) {
	path, remover := util.CreateTempDir("foo")
	defer remover()

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

	if directory.Name() != path {
		t.Errorf(util.FormatTestMessage("got incorrect name"), directory.Name(), path)
	}
}
Exemplo n.º 3
0
func TestEmptyDirectoryListing(t *testing.T) {
	path, remover := util.CreateTempDir("foo")
	defer remover()

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

	listing := directory.List()

	if listing.Size() != 0 {
		t.Errorf(util.FormatTestMessage("listing is not empty"), len(listing), 0)
	}

}