예제 #1
0
파일: server_test.go 프로젝트: heroku/busl
func TestPutWithBackend(t *testing.T) {
	uuid, _ := util.NewUUID()

	storage, _, put := fileServer(uuid)
	defer storage.Close()

	baseServer.StorageBaseURL = storage.URL
	defer func() {
		baseServer.StorageBaseURL = ""
	}()

	server := httptest.NewServer(baseServer.router())
	defer server.Close()

	transport := &http.Transport{}
	client := &http.Client{Transport: transport}

	registrar := broker.NewRedisRegistrar()
	registrar.Register(uuid)

	// uuid = curl -XPUT <url>/streams/1/2/3
	request, _ := http.NewRequest("POST", server.URL+"/streams/"+uuid, bytes.NewReader([]byte("hello world")))
	request.TransferEncoding = []string{"chunked"}
	resp, err := client.Do(request)
	defer resp.Body.Close()
	assert.Nil(t, err)
	assert.Equal(t, resp.StatusCode, 200)
	assert.Equal(t, <-put, []byte("hello world"))
}
예제 #2
0
파일: endpoints.go 프로젝트: heroku/busl
func (s *Server) createStream(w http.ResponseWriter, r *http.Request) {
	registrar := broker.NewRedisRegistrar()

	if err := registrar.Register(key(r)); err != nil {
		http.Error(w, "Unable to create stream. Please try again.", http.StatusServiceUnavailable)
		rollbar.Error(rollbar.ERR, fmt.Errorf("unable to register stream: %#v", err))
		util.CountWithData("put.create.fail", 1, "error=%s", err)
		return
	}
	util.Count("put.create.success")
	w.WriteHeader(http.StatusCreated)
}
예제 #3
0
파일: server_test.go 프로젝트: heroku/busl
func TestPut(t *testing.T) {
	server := httptest.NewServer(baseServer.router())
	defer server.Close()

	transport := &http.Transport{}
	client := &http.Client{Transport: transport}

	// uuid = curl -XPUT <url>/streams/1/2/3
	request, _ := http.NewRequest("PUT", server.URL+"/streams/1/2/3", nil)
	resp, err := client.Do(request)
	defer resp.Body.Close()
	assert.Nil(t, err)
	assert.Equal(t, resp.StatusCode, http.StatusCreated)

	registrar := broker.NewRedisRegistrar()
	assert.True(t, registrar.IsRegistered("1/2/3"))
}
예제 #4
0
파일: server_test.go 프로젝트: heroku/busl
func TestPubClosed(t *testing.T) {
	uuid, _ := util.NewUUID()

	registrar := broker.NewRedisRegistrar()
	err := registrar.Register(uuid)
	assert.Nil(t, err)
	writer, err := broker.NewWriter(uuid)
	assert.Nil(t, err)
	writer.Close()

	request, _ := http.NewRequest("POST", "/streams/"+uuid, nil)
	request.TransferEncoding = []string{"chunked"}
	response := httptest.NewRecorder()

	baseServer.publish(response, request)

	assert.Equal(t, response.Code, http.StatusNotFound)
}
예제 #5
0
파일: server.go 프로젝트: cyx/busl
func mkstream(w http.ResponseWriter, _ *http.Request) {
	registrar := broker.NewRedisRegistrar()
	uuid, err := util.NewUUID()
	if err != nil {
		http.Error(w, "Unable to create stream. Please try again.", http.StatusServiceUnavailable)
		rollbar.Error(rollbar.ERR, fmt.Errorf("unable to create new uuid for stream: %#v", err))
		util.CountWithData("mkstream.create.fail", 1, "error=%s", err)
		return
	}

	if err := registrar.Register(uuid); err != nil {
		http.Error(w, "Unable to create stream. Please try again.", http.StatusServiceUnavailable)
		rollbar.Error(rollbar.ERR, fmt.Errorf("unable to register stream: %#v", err))
		util.CountWithData("mkstream.create.fail", 1, "error=%s", err)
		return
	}

	util.Count("mkstream.create.success")
	io.WriteString(w, string(uuid))
}