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