Browse Source

Cover by tests all else handle funcs

Volodymyr Tkach 2 years ago
parent
commit
31a24800b0
1 changed files with 101 additions and 1 deletions
  1. 101 1
      utils/http/helpers/helpers_test.go

+ 101 - 1
utils/http/helpers/helpers_test.go

@@ -133,7 +133,7 @@ var _ = Describe("helpers", func() {
 			srv.Close()
 			srv.Close()
 		})
 		})
 
 
-		It("handle file", func() {
+		It("handle image png", func() {
 			resp, err := client.Get(srv.URL + "/")
 			resp, err := client.Get(srv.URL + "/")
 			Expect(err).To(Succeed())
 			Expect(err).To(Succeed())
 			defer resp.Body.Close()
 			defer resp.Body.Close()
@@ -148,6 +148,106 @@ var _ = Describe("helpers", func() {
 		})
 		})
 	})
 	})
 
 
+	Context("HandleTextCss", func() {
+		BeforeEach(func() {
+			srv = httptest.NewServer(helpers.HandleTextCss("MyContent"))
+			client = srv.Client()
+		})
+
+		AfterEach(func() {
+			srv.Close()
+		})
+
+		It("handle text css", func() {
+			resp, err := client.Get(srv.URL + "/")
+			Expect(err).To(Succeed())
+			defer resp.Body.Close()
+
+			Expect(resp.StatusCode).To(Equal(http.StatusOK))
+			Expect(resp.Header.Get("Content-Type")).To(Equal("text/css"))
+
+			body, err := io.ReadAll(resp.Body)
+			Expect(err).To(Succeed())
+
+			Expect(string(body)).To(Equal("MyContent"))
+		})
+	})
+
+	Context("HandleTextJavaScript", func() {
+		BeforeEach(func() {
+			srv = httptest.NewServer(helpers.HandleTextJavaScript("MyContent"))
+			client = srv.Client()
+		})
+
+		AfterEach(func() {
+			srv.Close()
+		})
+
+		It("handle text javascript", func() {
+			resp, err := client.Get(srv.URL + "/")
+			Expect(err).To(Succeed())
+			defer resp.Body.Close()
+
+			Expect(resp.StatusCode).To(Equal(http.StatusOK))
+			Expect(resp.Header.Get("Content-Type")).To(Equal("text/javascript"))
+
+			body, err := io.ReadAll(resp.Body)
+			Expect(err).To(Succeed())
+
+			Expect(string(body)).To(Equal("MyContent"))
+		})
+	})
+
+	Context("HandleTextPlain", func() {
+		BeforeEach(func() {
+			srv = httptest.NewServer(helpers.HandleTextPlain("MyContent"))
+			client = srv.Client()
+		})
+
+		AfterEach(func() {
+			srv.Close()
+		})
+
+		It("handle text plain", func() {
+			resp, err := client.Get(srv.URL + "/")
+			Expect(err).To(Succeed())
+			defer resp.Body.Close()
+
+			Expect(resp.StatusCode).To(Equal(http.StatusOK))
+			Expect(resp.Header.Get("Content-Type")).To(Equal("text/plain"))
+
+			body, err := io.ReadAll(resp.Body)
+			Expect(err).To(Succeed())
+
+			Expect(string(body)).To(Equal("MyContent"))
+		})
+	})
+
+	Context("HandleTextXml", func() {
+		BeforeEach(func() {
+			srv = httptest.NewServer(helpers.HandleTextXml("MyContent"))
+			client = srv.Client()
+		})
+
+		AfterEach(func() {
+			srv.Close()
+		})
+
+		It("handle text xml", func() {
+			resp, err := client.Get(srv.URL + "/")
+			Expect(err).To(Succeed())
+			defer resp.Body.Close()
+
+			Expect(resp.StatusCode).To(Equal(http.StatusOK))
+			Expect(resp.Header.Get("Content-Type")).To(Equal("text/xml"))
+
+			body, err := io.ReadAll(resp.Body)
+			Expect(err).To(Succeed())
+
+			Expect(string(body)).To(Equal("MyContent"))
+		})
+	})
+
 	Context("MinifyHtmlCode", func() {
 	Context("MinifyHtmlCode", func() {
 		It("minify Html code", func() {
 		It("minify Html code", func() {
 			Expect(helpers.MinifyHtmlCode(`
 			Expect(helpers.MinifyHtmlCode(`