Example #1
0
func Start(externalAddress string) {
	lock := &sync.RWMutex{}

	registered := []string{}

	server, serverAddr = helpers.Callback(externalAddress, func(w http.ResponseWriter, r *http.Request) {
		switch r.URL.Path {
		case "/announce":
			lock.Lock()
			registered = append(registered, r.URL.Query().Get("announcement"))
			lock.Unlock()
		case "/announcements":
			lock.RLock()
			json.NewEncoder(w).Encode(registered)
			lock.RUnlock()
		default:
			w.WriteHeader(http.StatusNotFound)
		}
	})
}
Example #2
0
		var server *httptest.Server
		var uploadAddr string

		var gotRequest chan struct{}

		BeforeEach(func() {
			guid = helpers.GenerateGuid()

			gotRequest = make(chan struct{})

			server, uploadAddr = helpers.Callback(componentMaker.ExternalAddress, ghttp.CombineHandlers(
				ghttp.VerifyRequest("POST", "/thingy"),
				func(w http.ResponseWriter, r *http.Request) {
					contents, err := ioutil.ReadAll(r.Body)
					Expect(err).NotTo(HaveOccurred())

					Expect(string(contents)).To(Equal("tasty thingy\n"))

					close(gotRequest)
				},
			))
		})

		AfterEach(func() {
			server.Close()
		})

		It("uploads the specified files", func() {
			err := receptorClient.CreateTask(helpers.TaskCreateRequest(
				guid,
				models.Serial(