func TestAddFile(t *testing.T) {
	s, dir := createTestServer(5, 8, 8, 0.000001, uint64(100000))
	defer os.RemoveAll(dir)
	c, cliDir := createTestClient(s, 0)
	defer os.RemoveAll(cliDir)
	content := "This is a simple test file"
	file := createTestFile(content)
	_, filename := path.Split(file)
	defer os.Remove(file)
	if c.AddFile(file) != nil {
		t.Fatalf("first time adding file fails")
	}
	if c.AddFile(file) == nil {
		t.Fatalf("same file added twice")
	}
	if c.lookupTable["0"] != filename {
		t.Fatalf("lookup table not set up correctly on the client")
	}
	if c.reverseLookup[filename] != "0" {
		t.Fatalf("reverse lookup table not set up correctly on the client")
	}
	serverLookupTable := make(map[string]string)
	if tableContent, found := s.ReadLookupTable(); found {
		json.Unmarshal(tableContent, &serverLookupTable)
	}
	if serverLookupTable["0"] != filename {
		t.Fatalf("lookup table not set up correctly on the server")
	}
	if actual, err := s.GetFile(0); err != nil || !bytes.Equal(actual, []byte(content)) {
		t.Fatalf("file not written correctly to the server: %s", err)
	}
	if !reflect.DeepEqual(s.SearchWord(c.indexer.ComputeTrapdoors("simple")), []int{0}) {
		t.Fatalf("index file not written correctly to server")
	}
	contentRead, err := ioutil.ReadFile(path.Join(cliDir, filename))
	if err != nil || !bytes.Equal(contentRead, []byte(content)) {
		t.Fatalf("file not correctly written to local client storage")
	}
}
TestAddFile tests the `AddFile` function.  Checks that the lookup tables are
correctly updated on both the server and the client, and that the file is
written correctly both on the client and the server and that the index is
correctly written on the server.
package client
import (
	"bytes"
	"encoding/json"
	"io/ioutil"
	"os"
	"path"
	"reflect"
	"search/prototype/server"
	"sort"
	"testing"
)
func createTestServer(numClients, lenMS, lenSalt int, fpRate float64, numUniqWords uint64) (*server.Server, string) {
	dir, err := ioutil.TempDir("", "serverTest")
	if err != nil {
		panic("cannot create the temporary test directory")
	}
	s, err2 := server.CreateServer(numClients, lenMS, lenSalt, dir, fpRate, numUniqWords)
	if err2 != nil {
		panic("error in creating the server")
	}
	return s, dir
}
func createTestClient(s *server.Server, clientNum int) (*Client, string) {
	dir, err := ioutil.TempDir("", "clientTest")
	if err != nil {
		panic("cannot create the temporary test directory")
	}
	c := CreateClient(s, clientNum, dir)
	return c, dir
}
func createTestFile(content string) string {
	doc, err := ioutil.TempFile("", "testFile")
	if err != nil {
		panic("cannot create the temporary test file")
	}
	if _, err := doc.Write([]byte(content)); err != nil {
		panic("cannot write to the temporary test file")
	}
	return doc.Name()
}
func TestCreateClient(t *testing.T) {
	s, dir := createTestServer(5, 8, 8, 0.000001, uint64(100000))
	defer os.RemoveAll(dir)
	c1, cliDir1 := createTestClient(s, 0)
	c2, cliDir2 := createTestClient(s, 1)
	defer os.RemoveAll(cliDir1)
	defer os.RemoveAll(cliDir2)
	if c1.server != c2.server {
		t.Fatalf("different servers for the clients")
	}
	if !reflect.DeepEqual(c1.lookupTable, c2.lookupTable) {
		t.Fatalf("different lookup tables for the clients")
	}
	if !reflect.DeepEqual(c1.indexer.ComputeTrapdoors("testing"), c2.indexer.ComputeTrapdoors("testing")) {
		t.Fatalf("different indexers for the clients")
	}
}