Exemplo n.º 1
0
	var mx *web.Mux // mux with the handlers we're testing

	BeforeEach(func() {
		settings = make(map[string]string)
		mx = NewMux()
		gojiutil.AddCommon15(mx, log15.Root())
		mx.Use(gojiutil.ParamsLogger(true)) // useful for troubleshooting
	})

	It("gets what it sets", func() {
		// set a value
		req, _ := http.NewRequest("PUT", "http://example.com/settings/hello?value=world",
			bytes.NewReader([]byte{}))
		resp := httptest.NewRecorder()
		mx.ServeHTTP(resp, req)
		Ω(resp.Code).Should(Equal(200))
		Ω(settings["hello"]).Should(Equal("world"))

		// get the value back
		req, _ = http.NewRequest("GET", "http://example.com/settings/hello", nil)
		resp = httptest.NewRecorder()
		mx.ServeHTTP(resp, req)
		Ω(resp.Code).Should(Equal(200))
		Ω(resp.Body.String()).Should(Equal("world"))
	})

	It("deletes and lists", func() {
		// set a value
		req, _ := http.NewRequest("PUT", "http://example.com/settings/hello?value=world",
			bytes.NewReader([]byte{}))