package helpers_test import ( "net/http" "testing" . "github.com/onsi/ginkgo" . "github.com/onsi/gomega" "github.com/vladimirok5959/golang-utils/utils/http/helpers" ) var _ = Describe("helpers", func() { Context("ClientIP", func() { It("return client IP", func() { Expect(helpers.ClientIP(&http.Request{ RemoteAddr: "127.0.0.1", })).To(Equal("127.0.0.1")) Expect(helpers.ClientIP(&http.Request{ RemoteAddr: "192.168.0.1,127.0.0.1", })).To(Equal("192.168.0.1")) Expect(helpers.ClientIP(&http.Request{ RemoteAddr: "192.168.0.1, 127.0.0.1", })).To(Equal("192.168.0.1")) Expect(helpers.ClientIP(&http.Request{ RemoteAddr: "192.168.0.50,192.168.0.1,127.0.0.1", })).To(Equal("192.168.0.50")) Expect(helpers.ClientIP(&http.Request{ RemoteAddr: "192.168.0.50, 192.168.0.1, 127.0.0.1", })).To(Equal("192.168.0.50")) }) }) Context("ClientIPs", func() { It("return array of client IPs", func() { Expect(helpers.ClientIPs(&http.Request{ RemoteAddr: "127.0.0.1", })).To(ConsistOf( "127.0.0.1", )) Expect(helpers.ClientIPs(&http.Request{ RemoteAddr: "192.168.0.1,127.0.0.1", })).To(ConsistOf( "192.168.0.1", "127.0.0.1", )) Expect(helpers.ClientIPs(&http.Request{ RemoteAddr: "192.168.0.1, 127.0.0.1", })).To(ConsistOf( "192.168.0.1", "127.0.0.1", )) Expect(helpers.ClientIPs(&http.Request{ RemoteAddr: "192.168.0.50,192.168.0.1,127.0.0.1", })).To(ConsistOf( "192.168.0.50", "192.168.0.1", "127.0.0.1", )) Expect(helpers.ClientIPs(&http.Request{ RemoteAddr: "192.168.0.50, 192.168.0.1, 127.0.0.1", })).To(ConsistOf( "192.168.0.50", "192.168.0.1", "127.0.0.1", )) }) }) Context("MinifyHtmlCode", func() { It("minify Html code", func() { Expect(helpers.MinifyHtmlCode(` Index `)).To(Equal(`Index`)) Expect(helpers.MinifyHtmlCode(`
Link 1, Link 2
`)).To(Equal(`
Link 1, Link 2
`)) Expect(helpers.MinifyHtmlCode(`
Contacts: Link 1, Link 2
`)).To(Equal(`
Contacts: Link 1, Link 2
`)) }) }) }) func TestSuite(t *testing.T) { RegisterFailHandler(Fail) RunSpecs(t, "helpers") }