github.com/loggregator/cli@v6.33.1-0.20180224010324-82334f081791+incompatible/cf/api/securitygroups/spaces/space_binder_test.go (about) 1 package spaces_test 2 3 import ( 4 "net/http" 5 "net/http/httptest" 6 "time" 7 8 "code.cloudfoundry.org/cli/cf/api/apifakes" 9 "code.cloudfoundry.org/cli/cf/configuration/coreconfig" 10 "code.cloudfoundry.org/cli/cf/net" 11 "code.cloudfoundry.org/cli/cf/terminal/terminalfakes" 12 testconfig "code.cloudfoundry.org/cli/util/testhelpers/configuration" 13 testnet "code.cloudfoundry.org/cli/util/testhelpers/net" 14 15 . "code.cloudfoundry.org/cli/cf/api/securitygroups/spaces" 16 "code.cloudfoundry.org/cli/cf/trace/tracefakes" 17 . "code.cloudfoundry.org/cli/util/testhelpers/matchers" 18 . "github.com/onsi/ginkgo" 19 . "github.com/onsi/gomega" 20 ) 21 22 var _ = Describe("SecurityGroupSpaceBinder", func() { 23 var ( 24 repo SecurityGroupSpaceBinder 25 gateway net.Gateway 26 testServer *httptest.Server 27 testHandler *testnet.TestHandler 28 configRepo coreconfig.ReadWriter 29 ) 30 31 BeforeEach(func() { 32 configRepo = testconfig.NewRepositoryWithDefaults() 33 gateway = net.NewCloudControllerGateway(configRepo, time.Now, new(terminalfakes.FakeUI), new(tracefakes.FakePrinter), "") 34 repo = NewSecurityGroupSpaceBinder(configRepo, gateway) 35 }) 36 37 AfterEach(func() { testServer.Close() }) 38 39 setupTestServer := func(reqs ...testnet.TestRequest) { 40 testServer, testHandler = testnet.NewServer(reqs) 41 configRepo.SetAPIEndpoint(testServer.URL) 42 } 43 44 Describe(".BindSpace", func() { 45 It("associates the security group with the space", func() { 46 setupTestServer( 47 apifakes.NewCloudControllerTestRequest(testnet.TestRequest{ 48 Method: "PUT", 49 Path: "/v2/security_groups/this-is-a-security-group-guid/spaces/yes-its-a-space-guid", 50 Response: testnet.TestResponse{ 51 Status: http.StatusCreated, 52 Body: ` 53 { 54 "metadata": {"guid": "fb6fdf81-ce1b-448f-ada9-09bbb8807812"}, 55 "entity": {"name": "dummy1", "rules": [] } 56 }`, 57 }, 58 })) 59 60 err := repo.BindSpace("this-is-a-security-group-guid", "yes-its-a-space-guid") 61 62 Expect(err).ToNot(HaveOccurred()) 63 Expect(testHandler).To(HaveAllRequestsCalled()) 64 }) 65 }) 66 67 Describe(".UnbindSpace", func() { 68 It("removes the associated security group from the space", func() { 69 setupTestServer( 70 apifakes.NewCloudControllerTestRequest(testnet.TestRequest{ 71 Method: "DELETE", 72 Path: "/v2/security_groups/this-is-a-security-group-guid/spaces/yes-its-a-space-guid", 73 Response: testnet.TestResponse{ 74 Status: http.StatusNoContent, 75 }, 76 })) 77 78 err := repo.UnbindSpace("this-is-a-security-group-guid", "yes-its-a-space-guid") 79 80 Expect(err).ToNot(HaveOccurred()) 81 Expect(testHandler).To(HaveAllRequestsCalled()) 82 }) 83 }) 84 })