Merge pull request #17 from 30x/XAPID-804

GET /deployments should return empty set, not 404
diff --git a/api.go b/api.go
index 0366f7f..ae92a0d 100644
--- a/api.go
+++ b/api.go
@@ -175,12 +175,6 @@
 		return
 	}
 
-	// send not found if no timeout
-	if len(deployments) == 0 && timeout == 0 {
-		w.WriteHeader(http.StatusNotFound)
-		return
-	}
-
 	// send results if different eTag
 	if eTag != ifNoneMatch {
 		sendDeployments(w, deployments, eTag)
@@ -198,14 +192,14 @@
 		if ifNoneMatch != "" {
 			w.WriteHeader(http.StatusNotModified)
 		} else {
-			w.WriteHeader(http.StatusNotFound)
+			sendDeployments(w, deployments, eTag)
 		}
 	}
 }
 
 func sendDeployments(w http.ResponseWriter, dataDeps []DataDeployment, eTag string) {
 
-	var apiDeps ApiDeploymentResponse
+	apiDeps := ApiDeploymentResponse{}
 
 	for _, d := range dataDeps {
 		apiDeps = append(apiDeps, ApiDeployment{
@@ -229,7 +223,7 @@
 		return
 	}
 
-	log.Debugf("sending deployment %s: %s", eTag, b)
+	log.Debugf("sending deployments %s: %s", eTag, b)
 	w.Header().Set("ETag", eTag)
 	w.Write(b)
 }
diff --git a/api_test.go b/api_test.go
index c95369f..373648d 100644
--- a/api_test.go
+++ b/api_test.go
@@ -3,20 +3,21 @@
 import (
 	"bytes"
 	"encoding/json"
-	. "github.com/onsi/ginkgo"
-	. "github.com/onsi/gomega"
 	"io/ioutil"
 	"net/http"
 	"net/http/httptest"
 	"net/url"
 	"time"
+
+	. "github.com/onsi/ginkgo"
+	. "github.com/onsi/gomega"
 )
 
 var _ = Describe("api", func() {
 
 	Context("GET /deployments", func() {
 
-		It("should get an empty array if no deployments", func() {
+		It("should get empty set if no deployments", func() {
 
 			uri, err := url.Parse(testServer.URL)
 			uri.Path = deploymentsEndpoint
@@ -24,7 +25,16 @@
 			res, err := http.Get(uri.String())
 			Expect(err).ShouldNot(HaveOccurred())
 			defer res.Body.Close()
-			Expect(res.StatusCode).Should(Equal(http.StatusNotFound))
+
+			Expect(res.StatusCode).Should(Equal(http.StatusOK))
+
+			var depRes ApiDeploymentResponse
+			body, err := ioutil.ReadAll(res.Body)
+			Expect(err).ShouldNot(HaveOccurred())
+			json.Unmarshal(body, &depRes)
+
+			Expect(len(depRes)).To(Equal(0))
+			Expect(string(body)).Should(Equal("[]"))
 		})
 
 		It("should debounce requests", func() {
@@ -50,6 +60,8 @@
 			Expect(err).ShouldNot(HaveOccurred())
 			defer res.Body.Close()
 
+			Expect(res.StatusCode).Should(Equal(http.StatusOK))
+
 			var depRes ApiDeploymentResponse
 			body, err := ioutil.ReadAll(res.Body)
 			Expect(err).ShouldNot(HaveOccurred())
@@ -103,14 +115,21 @@
 			query := uri.Query()
 			query.Add("block", "1")
 			uri.RawQuery = query.Encode()
+
 			res, err := http.Get(uri.String())
 			Expect(err).ShouldNot(HaveOccurred())
 			defer res.Body.Close()
 
+			var depRes ApiDeploymentResponse
+			body, err := ioutil.ReadAll(res.Body)
+			Expect(err).ShouldNot(HaveOccurred())
+			json.Unmarshal(body, &depRes)
+
 			Expect(res.StatusCode).Should(Equal(http.StatusOK))
+			Expect(string(body)).Should(Equal("[]"))
 		})
 
-		It("should get new deployment after blocking", func(done Done) {
+		It("should get new deployment set after blocking", func(done Done) {
 
 			deploymentID := "api_get_current_blocking"
 			insertTestDeployment(testServer, deploymentID)
@@ -301,6 +320,7 @@
 		})
 
 		It("should communicate status to tracking server", func() {
+
 			deploymentResults := apiDeploymentResults{
 				apiDeploymentResult{
 					ID:        "deploymentID",