func TestRemoveStorageFolderWithSector(t *testing.T) {
	if testing.Short() {
		t.SkipNow()
	}
	t.Parallel()
	cmt, err := newContractManagerTester("TestRemoveStorageFolderWithSector")
	if err != nil {
		t.Fatal(err)
	}
	defer cmt.panicClose()
	storageFolderDir := filepath.Join(cmt.persistDir, "storageFolderOne")
	err = os.MkdirAll(storageFolderDir, 0700)
	if err != nil {
		t.Fatal(err)
	}
	err = cmt.cm.AddStorageFolder(storageFolderDir, modules.SectorSize*storageFolderGranularity*2)
	if err != nil {
		t.Fatal(err)
	}
	root, data := randSector()
	err = cmt.cm.AddSector(root, data)
	if err != nil {
		t.Fatal(err)
	}
	sfs := cmt.cm.StorageFolders()
	if len(sfs) != 1 {
		t.Fatal("there should be storage folder in the contract manager")
	}
	if sfs[0].Capacity != sfs[0].CapacityRemaining+modules.SectorSize {
		t.Fatal("there should be one sector reported in the storage folder")
	}
	readData, err := cmt.cm.ReadSector(root)
	if err != nil {
		t.Fatal(err)
	}
	if !bytes.Equal(readData, data) {
		t.Fatal("Reading a sector from the storage folder did not produce the right data")
	}
	storageFolderTwo := filepath.Join(cmt.persistDir, "storageFolderTwo")
	err = os.MkdirAll(storageFolderTwo, 0700)
	if err != nil {
		t.Fatal(err)
	}
	err = cmt.cm.AddStorageFolder(storageFolderTwo, modules.SectorSize*storageFolderGranularity*2)
	if err != nil {
		t.Fatal(err)
	}
	err = cmt.cm.RemoveStorageFolder(sfs[0].Index, false)
	if err != nil {
		t.Fatal(err)
	}
	sfs = cmt.cm.StorageFolders()
	if len(sfs) != 1 {
		t.Fatal("there should be storage folder in the contract manager")
	}
	if sfs[0].Capacity != sfs[0].CapacityRemaining+modules.SectorSize {
		t.Fatal("there should be one sector reported in the storage folder")
	}
	readData, err = cmt.cm.ReadSector(root)
	if err != nil {
		t.Fatal(err)
	}
	if !bytes.Equal(readData, data) {
		t.Fatal("Reading a sector from the storage folder did not produce the right data")
	}
	_, err = os.Stat(filepath.Join(storageFolderDir, metadataFile))
	if !os.IsNotExist(err) {
		t.Error("metadata file should have been removed")
	}
	_, err = os.Stat(filepath.Join(storageFolderDir, sectorFile))
	if !os.IsNotExist(err) {
		t.Error("sector file should have been removed")
	}
	err = cmt.cm.Close()
	if err != nil {
		t.Fatal(err)
	}
	cmt.cm, err = New(filepath.Join(cmt.persistDir, modules.ContractManagerDir))
	if err != nil {
		t.Fatal(err)
	}
	sfs = cmt.cm.StorageFolders()
	if len(sfs) != 1 {
		t.Fatal("there should be storage folder in the contract manager")
	}
	if sfs[0].Capacity != sfs[0].CapacityRemaining+modules.SectorSize {
		t.Fatal("there should be one sector reported in the storage folder")
	}
	readData, err = cmt.cm.ReadSector(root)
	if err != nil {
		t.Fatal(err)
	}
	if !bytes.Equal(readData, data) {
		t.Fatal("Reading a sector from the storage folder did not produce the right data")
	}
}
TestRemoveStorageFolderWithSector tries removing a storage folder that has a
sector in it.
package contractmanager
import (
	"bytes"
	"os"
	"path/filepath"
	"sync"
	"testing"
	"github.com/NebulousLabs/Sia/crypto"
	"github.com/NebulousLabs/Sia/modules"
)
func TestRemoveStorageFolder(t *testing.T) {
	if testing.Short() {
		t.SkipNow()
	}
	t.Parallel()
	cmt, err := newContractManagerTester("TestRemoveStorageFolder")
	if err != nil {
		t.Fatal(err)
	}
	defer cmt.panicClose()
	storageFolderDir := filepath.Join(cmt.persistDir, "storageFolderOne")
	err = os.MkdirAll(storageFolderDir, 0700)
	if err != nil {
		t.Fatal(err)
	}
	err = cmt.cm.AddStorageFolder(storageFolderDir, modules.SectorSize*storageFolderGranularity*2)
	if err != nil {
		t.Fatal(err)
	}
	sfs := cmt.cm.StorageFolders()
	if len(sfs) != 1 {
		t.Fatal("there should be storage folder in the contract manager")
	}
	err = cmt.cm.RemoveStorageFolder(sfs[0].Index, false)
	if err != nil {
		t.Fatal(err)
	}
	sfs = cmt.cm.StorageFolders()
	if len(sfs) != 0 {
		t.Fatal("Storage folder should have been removed")
	}
	_, err = os.Stat(filepath.Join(storageFolderDir, metadataFile))
	if !os.IsNotExist(err) {
		t.Fatal("metadata file should have been removed")
	}
	_, err = os.Stat(filepath.Join(storageFolderDir, sectorFile))
	if !os.IsNotExist(err) {
		t.Fatal("sector file should have been removed")
	}
	err = cmt.cm.Close()
	if err != nil {
		t.Fatal(err)
	}
	cmt.cm, err = New(filepath.Join(cmt.persistDir, modules.ContractManagerDir))
	if err != nil {
		t.Fatal(err)
	}
	sfs = cmt.cm.StorageFolders()
	if len(sfs) != 0 {
		t.Fatal("Storage folder should have been removed")
	}
}