func setUpServer() (*server.Server, store.ObjectStore) { log.Println("Setting up test store and test server") teststore := store.NewMapStore() testserver := server.NewServer(teststore) testserver.Init() return testserver, teststore }
func main() { st := store.NewMapStore() s := server.NewServer(st) s.Init() s.AddResponder(impl.NewOrderAPIResponder(st)) s.AddResponder(impl.NewInventoryRequestResponder(st)) s.Open(address) }
func TestServerDelete(t *testing.T) { s := NewServer(store.NewMapStore()) s.Init() s.AddResponder(&Deleter{}) defer s.Close() a := makeAddress(ADDR, PORT+3) go s.Open(a) DoDelete(t, a, "/obj", 200) t.Log("Done") }
func TestServerPut(t *testing.T) { s := NewServer(store.NewMapStore()) s.Init() s.AddResponder(&Looper{}) defer s.Close() a := makeAddress(ADDR, PORT+2) go s.Open(a) DoPut(t, a, "/loop", "test", "application/text", 200, "test", func(r string, v string) bool { if r != v { t.Fail() t.Logf("Failed. Expected %s got %s", r, v) return false } return true }) t.Log("Done") }
func TestServerGet(t *testing.T) { s := NewServer(store.NewMapStore()) s.Init() s.AddResponder(&Messager{}) defer s.Close() a := makeAddress(ADDR, PORT+4) go s.Open(a) time.Sleep(time.Duration(1) * time.Second) t.Log("Sending GET") DoGet(t, a, "/msg/", 200, MSG, func(r string, v string) bool { if r != v { t.Fail() t.Logf("Failed. Expected %s got %s", r, v) return false } return true }) t.Log("Done") }