github.com/loggregator/cli@v6.33.1-0.20180224010324-82334f081791+incompatible/api/cloudcontroller/ccv2/codetemplates/delete_async_by_guid_test.go.template (about)

     1  package ccv2_test
     2  
     3  import (
     4  	"net/http"
     5  
     6  	"code.cloudfoundry.org/cli/api/cloudcontroller/ccerror"
     7  	. "code.cloudfoundry.org/cli/api/cloudcontroller/ccv2"
     8  	. "github.com/onsi/ginkgo"
     9  	. "github.com/onsi/gomega"
    10  	. "github.com/onsi/gomega/ghttp"
    11  )
    12  
    13  var _ = Describe("Delete{{.EntityName}}", func() {
    14  	var client *Client
    15  
    16  	BeforeEach(func() {
    17  		client = NewTestClient()
    18  	})
    19  
    20  	Context("when no errors are encountered", func() {
    21  		BeforeEach(func() {
    22  			jsonResponse := `{
    23  				"metadata": {
    24  					"guid": "job-guid",
    25  					"created_at": "2016-06-08T16:41:27Z",
    26  					"url": "/v2/jobs/job-guid"
    27  				},
    28  				"entity": {
    29  					"guid": "job-guid",
    30  					"status": "queued"
    31  				}
    32  			}`
    33  
    34  			server.AppendHandlers(
    35  				CombineHandlers(
    36  					VerifyRequest(http.MethodDelete, "/v2/{{.EntityNameSnake}}s/some-{{.EntityNameDashes}}-guid", "recursive=true&async=true"),
    37  					RespondWith(http.StatusAccepted, jsonResponse, http.Header{"X-Cf-Warnings": {"warning-1, warning-2"}}),
    38  				))
    39  		})
    40  
    41  		It("deletes the {{.EntityName}} and returns all warnings", func() {
    42  			job, warnings, err := client.Delete{{.EntityName}}("some-{{.EntityNameDashes}}-guid")
    43  
    44  			Expect(err).NotTo(HaveOccurred())
    45  			Expect(warnings).To(ConsistOf(Warnings{"warning-1", "warning-2"}))
    46  			Expect(job.GUID).To(Equal("job-guid"))
    47  			Expect(job.Status).To(Equal(JobStatusQueued))
    48  		})
    49  	})
    50  
    51  	Context("when an error is encountered", func() {
    52  		BeforeEach(func() {
    53  			response := `{
    54  "code": 30003,
    55  "description": "The {{.EntityName}} could not be found: some-{{.EntityNameDashes}}-guid",
    56  "error_code": "CF-{{.EntityName}}NotFound"
    57  }`
    58  			server.AppendHandlers(
    59  				CombineHandlers(
    60  					VerifyRequest(http.MethodDelete, "/v2/{{.EntityNameSnake}}s/some-{{.EntityNameDashes}}-guid", "recursive=true&async=true"),
    61  					RespondWith(http.StatusNotFound, response, http.Header{"X-Cf-Warnings": {"warning-1, warning-2"}}),
    62  				))
    63  		})
    64  
    65  		It("returns an error and all warnings", func() {
    66  			_, warnings, err := client.Delete{{.EntityName}}("some-{{.EntityNameDashes}}-guid")
    67  
    68  			Expect(err).To(MatchError(ccerror.ResourceNotFoundError{
    69  				Message: "The {{.EntityName}} could not be found: some-{{.EntityNameDashes}}-guid",
    70  			}))
    71  			Expect(warnings).To(ConsistOf(Warnings{"warning-1", "warning-2"}))
    72  		})
    73  	})
    74  })