github.com/jasonkeene/cli@v6.14.1-0.20160816203908-ca5715166dfb+incompatible/cf/api/strategy/endpoint_strategy_test.go (about)

     1  package strategy_test
     2  
     3  import (
     4  	"github.com/cloudfoundry/cli/cf/api/resources"
     5  	. "github.com/cloudfoundry/cli/cf/api/strategy"
     6  	. "github.com/onsi/ginkgo"
     7  	. "github.com/onsi/gomega"
     8  )
     9  
    10  var _ = Describe("EndpointStrategy", func() {
    11  	var strategy EndpointStrategy
    12  
    13  	Describe("events", func() {
    14  		Context("when the version string can't be parsed", func() {
    15  			BeforeEach(func() {
    16  				strategy = NewEndpointStrategy("")
    17  			})
    18  
    19  			It("uses the oldest possible strategy", func() {
    20  				Expect(strategy.EventsURL("the-guid", 20)).To(Equal("/v2/apps/the-guid/events?results-per-page=20"))
    21  				Expect(strategy.EventsResource()).To(BeAssignableToTypeOf(resources.EventResourceOldV2{}))
    22  			})
    23  		})
    24  
    25  		Context("when targeting a pre-2.1.0 cloud controller", func() {
    26  			BeforeEach(func() {
    27  				strategy = NewEndpointStrategy("2.0.0")
    28  			})
    29  
    30  			It("returns an appropriate endpoint", func() {
    31  				Expect(strategy.EventsURL("the-guid", 20)).To(Equal("/v2/apps/the-guid/events?results-per-page=20"))
    32  			})
    33  
    34  			It("returns an old EventResource", func() {
    35  				Expect(strategy.EventsResource()).To(BeAssignableToTypeOf(resources.EventResourceOldV2{}))
    36  			})
    37  		})
    38  
    39  		Context("when targeting a 2.1.0 cloud controller", func() {
    40  			BeforeEach(func() {
    41  				strategy = NewEndpointStrategy("2.1.0")
    42  			})
    43  
    44  			It("returns an appropriate endpoint", func() {
    45  				Expect(strategy.EventsURL("guids-r-us", 42)).To(Equal("/v2/events?order-direction=desc&q=actee%3Aguids-r-us&results-per-page=42"))
    46  			})
    47  
    48  			It("returns a new EventResource", func() {
    49  				Expect(strategy.EventsResource()).To(BeAssignableToTypeOf(resources.EventResourceNewV2{}))
    50  			})
    51  		})
    52  	})
    53  
    54  	Describe("domains", func() {
    55  		Context("when targeting a pre-2.1.0 cloud controller", func() {
    56  			BeforeEach(func() {
    57  				strategy = NewEndpointStrategy("2.0.0")
    58  			})
    59  
    60  			It("uses the general domains endpoint", func() {
    61  				Expect(strategy.PrivateDomainsURL()).To(Equal("/v2/domains"))
    62  			})
    63  		})
    64  
    65  		Context("when targeting a v2.1.0 cloud controller", func() {
    66  			BeforeEach(func() {
    67  				strategy = NewEndpointStrategy("2.1.0")
    68  			})
    69  
    70  			It("uses the private domains endpoint", func() {
    71  				Expect(strategy.PrivateDomainsURL()).To(Equal("/v2/private_domains"))
    72  			})
    73  		})
    74  	})
    75  })