github.com/pivotal-cf/go-pivnet/v6@v6.0.2/product_file_link_fetcher_test.go (about) 1 package pivnet_test 2 3 import ( 4 "github.com/onsi/gomega/ghttp" 5 "github.com/pivotal-cf/go-pivnet/v6" 6 "github.com/pivotal-cf/go-pivnet/v6/go-pivnetfakes" 7 "github.com/pivotal-cf/go-pivnet/v6/logger" 8 "github.com/pivotal-cf/go-pivnet/v6/logger/loggerfakes" 9 "net/http" 10 11 "fmt" 12 . "github.com/onsi/ginkgo" 13 . "github.com/onsi/gomega" 14 ) 15 16 var _ = Describe("PivnetClient - ProductFileLinkFetcher", func() { 17 var ( 18 server *ghttp.Server 19 client pivnet.Client 20 pivnetApiAddress string 21 22 newClientConfig pivnet.ClientConfig 23 fakeLogger logger.Logger 24 fakeAccessTokenService *gopivnetfakes.FakeAccessTokenService 25 ) 26 27 BeforeEach(func() { 28 server = ghttp.NewServer() 29 pivnetApiAddress = server.URL() 30 31 fakeLogger = &loggerfakes.FakeLogger{} 32 fakeAccessTokenService = &gopivnetfakes.FakeAccessTokenService{} 33 newClientConfig = pivnet.ClientConfig{ 34 Host: pivnetApiAddress, 35 } 36 client = pivnet.NewClient(fakeAccessTokenService, newClientConfig, fakeLogger) 37 }) 38 39 AfterEach(func() { 40 server.Close() 41 }) 42 43 Describe("NewDownloadLink", func() { 44 It("returns a url", func() { 45 server.AppendHandlers( 46 ghttp.CombineHandlers( 47 ghttp.VerifyRequest("POST", fmt.Sprintf("%s/test-endpoint", apiPrefix)), 48 ghttp.RespondWith(http.StatusFound, nil, 49 http.Header{ 50 "Location": []string{"http://example.com"}, 51 }, 52 ), 53 ), 54 ) 55 56 linkFetcher := pivnet.NewProductFileLinkFetcher("/test-endpoint", client) 57 link, err := linkFetcher.NewDownloadLink() 58 Expect(err).NotTo(HaveOccurred()) 59 Expect(link).To(Equal("http://example.com")) 60 }) 61 }) 62 })