github.com/sap/cf-mta-plugin@v2.6.3+incompatible/clients/restclient/rest_client_test.go (about)

     1  package restclient_test
     2  
     3  import (
     4  	"github.com/cloudfoundry-incubator/multiapps-cli-plugin/clients/baseclient"
     5  	"github.com/cloudfoundry-incubator/multiapps-cli-plugin/clients/restclient"
     6  	"github.com/cloudfoundry-incubator/multiapps-cli-plugin/testutil"
     7  	. "github.com/onsi/ginkgo"
     8  	. "github.com/onsi/gomega"
     9  	"net/http"
    10  )
    11  
    12  var _ = Describe("RestClient", func() {
    13  
    14  	Describe("PurgeConfiguration", func() {
    15  		Context("when the backend returns not 204 No Content", func() {
    16  			It("should return an error", func() {
    17  				client := newRestClient(http.StatusInternalServerError)
    18  				err := client.PurgeConfiguration("org", "space")
    19  				Ω(err).Should(HaveOccurred())
    20  			})
    21  		})
    22  
    23  		Context("when the backend returns 204 No Content", func() {
    24  			It("should not return an error", func() {
    25  				client := newRestClient(http.StatusNoContent)
    26  				err := client.PurgeConfiguration("org", "space")
    27  				Ω(err).ShouldNot(HaveOccurred())
    28  			})
    29  		})
    30  	})
    31  })
    32  
    33  func newRestClient(statusCode int) restclient.RestClientOperations {
    34  	tokenFactory := baseclient.NewCustomTokenFactory("test-token")
    35  	roundTripper := testutil.NewCustomTransport(statusCode)
    36  	return restclient.NewRestClient("http://localhost:1000", roundTripper, tokenFactory)
    37  }