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