github.com/IBM-Cloud/bluemix-go@v0.0.0-20240423071914-9e96525baef4/api/container/containerv1/properties_test.go (about) 1 package containerv1 2 3 import ( 4 "log" 5 "net/http" 6 7 bluemix "github.com/IBM-Cloud/bluemix-go" 8 "github.com/IBM-Cloud/bluemix-go/client" 9 bluemixHttp "github.com/IBM-Cloud/bluemix-go/http" 10 "github.com/IBM-Cloud/bluemix-go/session" 11 12 "github.com/onsi/gomega/ghttp" 13 14 . "github.com/onsi/ginkgo" 15 . "github.com/onsi/gomega" 16 ) 17 18 var _ = Describe("Vlans", func() { 19 var server *ghttp.Server 20 AfterEach(func() { 21 server.Close() 22 }) 23 24 //List 25 Describe("List", func() { 26 Context("When read of vlans is successful", func() { 27 BeforeEach(func() { 28 server = ghttp.NewServer() 29 server.AppendHandlers( 30 ghttp.CombineHandlers( 31 ghttp.VerifyRequest(http.MethodGet, "/v1/datacenters/dal10/vlans"), 32 ghttp.RespondWith(http.StatusOK, `[ 33 { 34 "id": "12345", 35 "type": "private", 36 "properties": { 37 "name": "", 38 "note": "", 39 "primary_router": "something.dal10", 40 "vlan_number": "1111", 41 "vlan_type": "standard", 42 "location": "11", 43 "local_disk_storage_capability": "true", 44 "san_storage_capability": "true" 45 } 46 }]`), 47 ), 48 ) 49 }) 50 51 It("should return cluster list", func() { 52 target := ClusterTargetHeader{ 53 OrgID: "abc", 54 SpaceID: "def", 55 AccountID: "ghi", 56 Region: "eu-de", 57 } 58 59 vlans, err := newVlan(server.URL()).List("dal10", target) 60 Expect(vlans).ShouldNot(BeNil()) 61 for _, vlan := range vlans { 62 Expect(err).NotTo(HaveOccurred()) 63 Expect(vlan.ID).Should(Equal("12345")) 64 } 65 }) 66 }) 67 Context("When read of vlans is unsuccessful", func() { 68 BeforeEach(func() { 69 server = ghttp.NewServer() 70 server.SetAllowUnhandledRequests(true) 71 server.AppendHandlers( 72 ghttp.CombineHandlers( 73 ghttp.VerifyRequest(http.MethodGet, "/v1/datacenters/fakedc/vlans"), 74 ghttp.RespondWith(http.StatusInternalServerError, `Failed to retrieve vlans`), 75 ), 76 ) 77 }) 78 79 It("should return error when cluster are retrieved", func() { 80 target := ClusterTargetHeader{ 81 OrgID: "abc", 82 SpaceID: "def", 83 AccountID: "ghi", 84 Region: "eu-de", 85 } 86 87 vlans, err := newVlan(server.URL()).List("fakedc", target) 88 Expect(err).To(HaveOccurred()) 89 Expect(vlans).Should(BeNil()) 90 }) 91 }) 92 }) 93 // 94 }) 95 96 func newVlan(url string) Vlans { 97 98 sess, err := session.New() 99 if err != nil { 100 log.Fatal(err) 101 } 102 conf := sess.Config.Copy() 103 conf.HTTPClient = bluemixHttp.NewHTTPClient(conf) 104 conf.Endpoint = &url 105 106 client := client.Client{ 107 Config: conf, 108 ServiceName: bluemix.MccpService, 109 } 110 return newVlanAPI(&client) 111 }